create-expo-updates-server 0.2.1 → 0.4.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/README.md +1 -1
- package/dist/template/app/updates/[encodedKey]/page.tsx +55 -33
- package/dist/template/app/updates/devices/page.tsx +13 -7
- package/dist/template/app/updates/embedded/page.tsx +25 -13
- package/dist/template/app/updates/emergency-redirects/page.tsx +70 -38
- package/dist/template/app/updates/page.tsx +33 -20
- package/dist/template/components/admin/admin-shell.tsx +11 -5
- package/dist/template/components/admin/language-switcher.tsx +5 -2
- package/dist/template/components/ui/dialog.tsx +13 -4
- package/dist/template/components/ui/sheet.tsx +6 -2
- package/dist/template/components/ui/sidebar.tsx +62 -17
- package/dist/template/docs/admin-ui.md +18 -24
- package/dist/template/docs/device-targeting.md +4 -5
- package/dist/template/docs/expo-app-setup.md +8 -12
- package/dist/template/docs/getting-started.md +5 -5
- package/dist/template/docs/getting-started.ru.md +11 -544
- package/dist/template/docs/index.md +1 -1
- package/dist/template/docs/installation-telemetry.md +4 -4
- package/dist/template/docs/operations-guide.md +1 -1
- package/dist/template/docs/ota-client-lifecycle.md +46 -42
- package/dist/template/docs/ota-emergency-recovery.md +34 -57
- package/dist/template/docs/ru/admin-ui.md +29 -0
- package/dist/template/docs/ru/device-targeting.md +59 -0
- package/dist/template/docs/ru/doctor.md +98 -0
- package/dist/template/docs/ru/expo-app-setup.md +497 -0
- package/dist/template/docs/ru/getting-started.md +391 -0
- package/dist/template/docs/ru/index.md +50 -0
- package/dist/template/docs/ru/installation-telemetry.md +125 -0
- package/dist/template/docs/ru/npm-installer.md +71 -0
- package/dist/template/docs/ru/operations-guide.md +317 -0
- package/dist/template/docs/ru/ota-client-lifecycle.md +167 -0
- package/dist/template/docs/ru/ota-emergency-recovery.md +108 -0
- package/dist/template/docs/ru/ota-update-policy.md +67 -0
- package/dist/template/docs/ru/publishing-npm-installer.md +49 -0
- package/dist/template/docs/ru/supabase-setup.md +120 -0
- package/dist/template/docs/uk/admin-ui.md +29 -0
- package/dist/template/docs/uk/device-targeting.md +59 -0
- package/dist/template/docs/uk/doctor.md +98 -0
- package/dist/template/docs/uk/expo-app-setup.md +497 -0
- package/dist/template/docs/uk/getting-started.md +391 -0
- package/dist/template/docs/uk/index.md +50 -0
- package/dist/template/docs/uk/installation-telemetry.md +125 -0
- package/dist/template/docs/uk/npm-installer.md +71 -0
- package/dist/template/docs/uk/operations-guide.md +317 -0
- package/dist/template/docs/uk/ota-client-lifecycle.md +167 -0
- package/dist/template/docs/uk/ota-emergency-recovery.md +108 -0
- package/dist/template/docs/uk/ota-update-policy.md +67 -0
- package/dist/template/docs/uk/publishing-npm-installer.md +49 -0
- package/dist/template/docs/uk/supabase-setup.md +120 -0
- package/dist/template/package-lock.json +589 -0
- package/dist/template/package.json +2 -0
- package/dist/template/scripts/lib/device-identity.test.ts +2 -2
- package/dist/template/scripts/lib/doctor.mjs +3 -3
- package/dist/template/scripts/lib/doctor.test.mjs +1 -1
- package/dist/template/scripts/lib/ota-client-configurator.mjs +116 -34
- package/dist/template/scripts/lib/ota-client-configurator.test.ts +210 -61
- package/dist/template/scripts/lib/ota-client.test.ts +1 -1
- package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +435 -118
- package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +243 -86
- package/dist/template/scripts/lib/ota-update-controller.test.ts +10 -9
- package/dist/template/scripts/lib/ota-updates-ui.test.tsx +154 -0
- package/dist/template/scripts/tests/fixtures/react-native-ui.tsx +34 -0
- package/dist/template/scripts/tests/ota-client-types.mjs +69 -0
- package/dist/template/src/client/devices/analytics.tsx +21 -8
- package/dist/template/src/client/devices/device-name.tsx +3 -1
- package/dist/template/src/client/devices/registry.tsx +38 -19
- package/dist/template/src/client/devices/version-adoption-chart.tsx +22 -10
- package/dist/template/src/client/distribution-control.tsx +27 -14
- package/dist/template/src/client/guard-action-combobox.test.ts +1 -1
- package/dist/template/src/client/guard-action-combobox.tsx +16 -10
- package/dist/template/src/client/i18n/en.json +203 -1
- package/dist/template/src/client/i18n/language-switching.test.tsx +224 -0
- package/dist/template/src/client/i18n/messages.test.ts +102 -19
- package/dist/template/src/client/i18n/messages.ts +31 -16
- package/dist/template/src/client/i18n/provider.tsx +6 -3
- package/dist/template/src/client/i18n/ru.json +488 -0
- package/dist/template/src/client/i18n/uk.json +488 -0
- package/dist/template/src/client/i18n/use-formatters.ts +5 -0
- package/dist/template/src/client/update-audience-editor.tsx +18 -11
- package/dist/template/src/client/update-policy-editor.tsx +64 -39
- package/dist/template/templates/expo-app/ota-client/README.md +16 -2
- package/dist/template/templates/expo-app/ota-client/controller.ts +107 -0
- package/dist/template/templates/expo-app/ota-client/device-identity.ts +48 -0
- package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +18 -9
- package/dist/template/templates/expo-app/ota-client/index.ts +16 -0
- package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.ts +97 -0
- package/dist/template/templates/expo-app/ota-client/model/update-controller.ts +293 -0
- package/dist/template/templates/expo-app/ota-client/runtime.ts +153 -0
- package/dist/template/templates/expo-app/ota-client/types.ts +85 -0
- package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.tsx +25 -0
- package/dist/template/templates/expo-app/ota-client/ui/ota-updates.tsx +196 -0
- package/dist/template/tsconfig.json +3 -1
- package/dist/template/vitest.config.mts +3 -0
- package/dist/template-manifest.json +302 -127
- package/package.json +1 -1
- package/dist/template/templates/expo-app/ota-client/controller.js +0 -60
- package/dist/template/templates/expo-app/ota-client/device-identity.js +0 -26
- package/dist/template/templates/expo-app/ota-client/index.d.ts +0 -47
- package/dist/template/templates/expo-app/ota-client/index.js +0 -3
- package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.js +0 -48
- package/dist/template/templates/expo-app/ota-client/model/update-controller.js +0 -182
- package/dist/template/templates/expo-app/ota-client/runtime.js +0 -112
- package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.js +0 -56
|
@@ -282,5 +282,207 @@
|
|
|
282
282
|
"Страница ": "Page ",
|
|
283
283
|
"Вперёд": "Next",
|
|
284
284
|
"Неверные учётные данные": "Invalid credentials",
|
|
285
|
-
"Вход временно недоступен": "Login is temporarily unavailable"
|
|
285
|
+
"Вход временно недоступен": "Login is temporarily unavailable",
|
|
286
|
+
"Interface language": "Interface language",
|
|
287
|
+
"Release workspace": "Release workspace",
|
|
288
|
+
"Native:": "Native:",
|
|
289
|
+
"Runtime": "Runtime",
|
|
290
|
+
"Embedded": "Embedded",
|
|
291
|
+
"Native": "Native",
|
|
292
|
+
"Emergency": "Emergency",
|
|
293
|
+
"Runtime / native": "Runtime / native",
|
|
294
|
+
"Rule action": "Rule action",
|
|
295
|
+
"Action (required)": "Action (required)",
|
|
296
|
+
"Guard action catalog": "Guard action catalog",
|
|
297
|
+
"Delete from catalog": "Delete from catalog",
|
|
298
|
+
"No matching actions": "No matching actions",
|
|
299
|
+
"Toggle Sidebar": "Toggle Sidebar",
|
|
300
|
+
"Close": "Close",
|
|
301
|
+
"Device IDs": "Device IDs",
|
|
302
|
+
"Installation IDs": "Installation IDs",
|
|
303
|
+
"Read only · updates:write": "Read only · updates:write",
|
|
304
|
+
"· version": "· version",
|
|
305
|
+
"Update policy": "Update policy",
|
|
306
|
+
"Manual": "Manual",
|
|
307
|
+
"Background": "Background",
|
|
308
|
+
"Published policies are read-only. Publish a new update ID to change policy.": "Published policies are read-only. Publish a new update ID to change policy.",
|
|
309
|
+
"Note:": "Note:",
|
|
310
|
+
"a Guard is usually paired with Background delivery so the candidate can fetch silently. Activation is still allowed.": "a Guard is usually paired with Background delivery so the candidate can fetch silently. Activation is still allowed.",
|
|
311
|
+
"Action catalog:": "Action catalog:",
|
|
312
|
+
"Add action to catalog": "Add action to catalog",
|
|
313
|
+
"Reusable action name": "Reusable action name",
|
|
314
|
+
"Adds a reusable catalog item without changing this policy.": "Adds a reusable catalog item without changing this policy.",
|
|
315
|
+
"Action catalog": "Action catalog",
|
|
316
|
+
"Guard action catalog entries": "Guard action catalog entries",
|
|
317
|
+
"No catalog actions found.": "No catalog actions found.",
|
|
318
|
+
"Guard enabled": "Guard enabled",
|
|
319
|
+
"When enabled, this Guard applies unconditionally whenever this OTA is selected for a client.": "When enabled, this Guard applies unconditionally whenever this OTA is selected for a client.",
|
|
320
|
+
"Optional custom JSON payload": "Optional custom JSON payload",
|
|
321
|
+
"No Guard will be emitted in the update manifest.": "No Guard will be emitted in the update manifest.",
|
|
322
|
+
"Save policy": "Save policy",
|
|
323
|
+
"Installation ID": "Installation ID",
|
|
324
|
+
"Device ID": "Device ID",
|
|
325
|
+
"Stage": "Stage",
|
|
326
|
+
"Latest": "Latest",
|
|
327
|
+
"Rollback": "Rollback",
|
|
328
|
+
"Guard": "Guard",
|
|
329
|
+
"Policy": "Policy",
|
|
330
|
+
"Assets": "Assets",
|
|
331
|
+
"Update ID": "Update ID",
|
|
332
|
+
"Promote": "Promote",
|
|
333
|
+
"Created At": "Created At",
|
|
334
|
+
"App version": "App version",
|
|
335
|
+
"Embedded ID": "Embedded ID",
|
|
336
|
+
"Action": "Action",
|
|
337
|
+
"OTA Updates": "OTA Updates",
|
|
338
|
+
"Rollback lock:": "Rollback lock:",
|
|
339
|
+
"Runtime / App": "Runtime / App",
|
|
340
|
+
"App": "App",
|
|
341
|
+
"Runtime version": "Runtime version",
|
|
342
|
+
"Embedded update ID": "Embedded update ID",
|
|
343
|
+
"From channel": "From channel",
|
|
344
|
+
"To channel": "To channel",
|
|
345
|
+
"Target mode": "Target mode",
|
|
346
|
+
"Pinned update": "Pinned update",
|
|
347
|
+
"Follow channel": "Follow channel",
|
|
348
|
+
"Scope": "Scope",
|
|
349
|
+
"Redirect": "Redirect",
|
|
350
|
+
"Target": "Target",
|
|
351
|
+
"Actions": "Actions",
|
|
352
|
+
"Edit": "Edit",
|
|
353
|
+
"Read only": "Read only",
|
|
354
|
+
"Expected update ID": "Expected update ID",
|
|
355
|
+
"Expected update ID (optional)": "Expected update ID (optional)",
|
|
356
|
+
"Enabled": "Enabled",
|
|
357
|
+
"Disabled": "Disabled",
|
|
358
|
+
"Disable": "Disable",
|
|
359
|
+
"Enable": "Enable",
|
|
360
|
+
"Adding…": "Adding…",
|
|
361
|
+
"Add to catalog": "Add to catalog",
|
|
362
|
+
"Ignored by rollback": "Ignored by rollback",
|
|
363
|
+
"Scope open": "Scope open",
|
|
364
|
+
"None": "None",
|
|
365
|
+
"draft": "draft",
|
|
366
|
+
"published": "published",
|
|
367
|
+
"active": "active",
|
|
368
|
+
"inactive": "inactive",
|
|
369
|
+
"disabled": "disabled",
|
|
370
|
+
"admin": "admin",
|
|
371
|
+
"operator": "operator",
|
|
372
|
+
"viewer": "viewer",
|
|
373
|
+
"Native version / build": "Native version / build",
|
|
374
|
+
"OTA artifact ID": "OTA artifact ID",
|
|
375
|
+
"Launch update ID": "Launch update ID",
|
|
376
|
+
"Runtime {0}": "Runtime {0}",
|
|
377
|
+
"Loading update policy…": "Loading update policy…",
|
|
378
|
+
"Delete \"{0}\" from the action catalog? Existing policies are unaffected.": "Delete \"{0}\" from the action catalog? Existing policies are unaffected.",
|
|
379
|
+
"Policy saved as version {0}.": "Policy saved as version {0}.",
|
|
380
|
+
" · published {0}": " · published {0}",
|
|
381
|
+
" · draft": " · draft",
|
|
382
|
+
"Delete {0} from action catalog": "Delete {0} from action catalog",
|
|
383
|
+
"Create “{0}”": "Create “{0}”",
|
|
384
|
+
"Failed to load action catalog": "Failed to load action catalog",
|
|
385
|
+
"Failed to load policy": "Failed to load policy",
|
|
386
|
+
"Action remains selected but was not saved to the catalog.": "Action remains selected but was not saved to the catalog.",
|
|
387
|
+
"Failed to add action to the catalog.": "Failed to add action to the catalog.",
|
|
388
|
+
"Failed to delete action from catalog": "Failed to delete action from catalog",
|
|
389
|
+
"Select or create a Guard action.": "Select or create a Guard action.",
|
|
390
|
+
"Guard payload must be valid JSON.": "Guard payload must be valid JSON.",
|
|
391
|
+
"Failed to save policy": "Failed to save policy",
|
|
392
|
+
"Action must contain between 1 and 100 characters.": "Action must contain between 1 and 100 characters.",
|
|
393
|
+
"Action must not contain control characters.": "Action must not contain control characters.",
|
|
394
|
+
"Rules: {0}": "Rules: {0}",
|
|
395
|
+
"Builds: {0}": "Builds: {0}",
|
|
396
|
+
"Ascending": "Ascending",
|
|
397
|
+
"Descending": "Descending",
|
|
398
|
+
"Unauthorized": "Unauthorized",
|
|
399
|
+
"Forbidden": "Forbidden",
|
|
400
|
+
"Invalid filters": "Invalid filters",
|
|
401
|
+
"Device report unavailable": "Device report unavailable",
|
|
402
|
+
"Invalid platform": "Invalid platform",
|
|
403
|
+
"Invalid device ID": "Invalid device ID",
|
|
404
|
+
"Device name unavailable": "Device name unavailable",
|
|
405
|
+
"Devices unavailable": "Devices unavailable",
|
|
406
|
+
"Invalid device name": "Invalid device name",
|
|
407
|
+
"Failed to name device": "Failed to name device",
|
|
408
|
+
"Invalid JSON request body": "Invalid JSON request body",
|
|
409
|
+
"Invalid JSON request body.": "Invalid JSON request body.",
|
|
410
|
+
"Invalid request body": "Invalid request body",
|
|
411
|
+
"Request body must be a JSON object.": "Request body must be a JSON object.",
|
|
412
|
+
"Failed to list emergency redirects": "Failed to list emergency redirects",
|
|
413
|
+
"Failed to create emergency redirect": "Failed to create emergency redirect",
|
|
414
|
+
"Failed to update emergency redirect": "Failed to update emergency redirect",
|
|
415
|
+
"Failed to delete emergency redirect": "Failed to delete emergency redirect",
|
|
416
|
+
"Failed to read OTA distribution control.": "Failed to read OTA distribution control.",
|
|
417
|
+
"Failed to update OTA distribution control.": "Failed to update OTA distribution control.",
|
|
418
|
+
"Failed to list guard actions": "Failed to list guard actions",
|
|
419
|
+
"Failed to create guard action": "Failed to create guard action",
|
|
420
|
+
"Failed to delete guard action": "Failed to delete guard action",
|
|
421
|
+
"Audience unavailable": "Audience unavailable",
|
|
422
|
+
"Update not found": "Update not found",
|
|
423
|
+
"Failed to fetch updates": "Failed to fetch updates",
|
|
424
|
+
"Failed to fetch update": "Failed to fetch update",
|
|
425
|
+
"Failed to fetch embedded updates": "Failed to fetch embedded updates",
|
|
426
|
+
"Failed to delete embedded update": "Failed to delete embedded update",
|
|
427
|
+
"Failed to fetch update policy": "Failed to fetch update policy",
|
|
428
|
+
"Failed to update policy": "Failed to update policy",
|
|
429
|
+
"Failed to promote latest update": "Failed to promote latest update",
|
|
430
|
+
"Failed to deactivate update": "Failed to deactivate update",
|
|
431
|
+
"Failed to delete update": "Failed to delete update",
|
|
432
|
+
"Failed to update JSON": "Failed to update JSON",
|
|
433
|
+
"Failed to rollback update": "Failed to rollback update",
|
|
434
|
+
"Failed to fetch": "Failed to fetch",
|
|
435
|
+
"Load failed": "Load failed",
|
|
436
|
+
"Emergency redirect must be a JSON object": "Emergency redirect must be a JSON object",
|
|
437
|
+
"Patch must be a JSON object": "Patch must be a JSON object",
|
|
438
|
+
"name must be a non-empty string": "name must be a non-empty string",
|
|
439
|
+
"embeddedUpdateId must be a non-empty string": "embeddedUpdateId must be a non-empty string",
|
|
440
|
+
"runtimeVersion must be a non-empty string": "runtimeVersion must be a non-empty string",
|
|
441
|
+
"fromChannel must be a non-empty string": "fromChannel must be a non-empty string",
|
|
442
|
+
"toChannel must be a non-empty string": "toChannel must be a non-empty string",
|
|
443
|
+
"name must contain at most 120 characters": "name must contain at most 120 characters",
|
|
444
|
+
"embeddedUpdateId must be a UUID": "embeddedUpdateId must be a UUID",
|
|
445
|
+
"platform must be android or ios": "platform must be android or ios",
|
|
446
|
+
"fromChannel and toChannel must differ": "fromChannel and toChannel must differ",
|
|
447
|
+
"targetMode must be pinned or follow": "targetMode must be pinned or follow",
|
|
448
|
+
"enabled must be boolean": "enabled must be boolean",
|
|
449
|
+
"expectedUpdateId is required in pinned mode": "expectedUpdateId is required in pinned mode",
|
|
450
|
+
"expectedUpdateId must be a UUID": "expectedUpdateId must be a UUID",
|
|
451
|
+
"Invalid audience": "Invalid audience",
|
|
452
|
+
"Invalid target IDs (maximum 100 per type)": "Invalid target IDs (maximum 100 per type)",
|
|
453
|
+
"Invalid audience mode or version": "Invalid audience mode or version",
|
|
454
|
+
"Select at least one device or installation": "Select at least one device or installation",
|
|
455
|
+
"Audience changed or distribution blocked. Refresh and try again.": "Audience changed or distribution blocked. Refresh and try again.",
|
|
456
|
+
"Failed to save audience": "Failed to save audience",
|
|
457
|
+
"Guard action must be a JSON object": "Guard action must be a JSON object",
|
|
458
|
+
"actionKey must be a string": "actionKey must be a string",
|
|
459
|
+
"actionKey must contain between 1 and 100 characters": "actionKey must contain between 1 and 100 characters",
|
|
460
|
+
"actionKey must not contain control characters": "actionKey must not contain control characters",
|
|
461
|
+
"id must be a UUID": "id must be a UUID",
|
|
462
|
+
"expectedPolicyVersion must be a positive integer.": "expectedPolicyVersion must be a positive integer.",
|
|
463
|
+
"Update policy is immutable after publication.": "Update policy is immutable after publication.",
|
|
464
|
+
"reason is required when OTA distribution is blocked.": "reason is required when OTA distribution is blocked.",
|
|
465
|
+
"reason must contain at most 500 characters and no control characters.": "reason must contain at most 500 characters and no control characters.",
|
|
466
|
+
"content must be a JSON object": "content must be a JSON object",
|
|
467
|
+
"Cannot promote: latest update is not set for this scope.": "Cannot promote: latest update is not set for this scope.",
|
|
468
|
+
"Promote is allowed only on the latest update.": "Promote is allowed only on the latest update.",
|
|
469
|
+
"Promote is not available because rollback is not active.": "Promote is not available because rollback is not active.",
|
|
470
|
+
"Rollback is not available: no active update is currently served for this scope.": "Rollback is not available: no active update is currently served for this scope.",
|
|
471
|
+
"Rollback is not available for the currently served update.": "Rollback is not available for the currently served update.",
|
|
472
|
+
"Rollback is not available: currently served update is not active.": "Rollback is not available: currently served update is not active.",
|
|
473
|
+
"Rollback is allowed only when a newer active update exists in the same scope.": "Rollback is allowed only when a newer active update exists in the same scope.",
|
|
474
|
+
"Direct activation is allowed only for the newest update in scope. Use Rollback for older updates.": "Direct activation is allowed only for the newest update in scope. Use Rollback for older updates.",
|
|
475
|
+
"Direct activation is unavailable while rollback mode is active. Use Promote on the newest update.": "Direct activation is unavailable while rollback mode is active. Use Promote on the newest update.",
|
|
476
|
+
"Version {0}": "Version {0}",
|
|
477
|
+
" · version {0}": " · version {0}",
|
|
478
|
+
"policy.delivery: must be manual or background": "policy.delivery: must be manual or background",
|
|
479
|
+
"policy.guard.action: must be a string": "policy.guard.action: must be a string",
|
|
480
|
+
"policy.guard.payload: must be absent when action is empty": "policy.guard.payload: must be absent when action is empty",
|
|
481
|
+
"policy.guard.action: must contain at most 100 characters": "policy.guard.action: must contain at most 100 characters",
|
|
482
|
+
"policy.guard.payload: must be JSON-serializable": "policy.guard.payload: must be JSON-serializable",
|
|
483
|
+
"Distribution control version conflict. Refresh and try again.": "Distribution control version conflict. Refresh and try again.",
|
|
484
|
+
"OTA distribution is globally blocked. Disable the emergency switch before starting distribution.": "OTA distribution is globally blocked. Disable the emergency switch before starting distribution.",
|
|
485
|
+
"policy.guard.action: must be trimmed, contain 1-100 characters, and have no control characters": "policy.guard.action: must be trimmed, contain 1-100 characters, and have no control characters",
|
|
486
|
+
"policy.guard.payload: must not exceed 16384 UTF-8 bytes": "policy.guard.payload: must not exceed 16384 UTF-8 bytes",
|
|
487
|
+
"policy.guard.payload: JSON depth must not exceed 10": "policy.guard.payload: JSON depth must not exceed 10"
|
|
286
488
|
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from "react";
|
|
3
|
+
import { createRoot, type Root } from "react-dom/client";
|
|
4
|
+
import { renderToString } from "react-dom/server";
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { LanguageSwitcher } from "@/components/admin/language-switcher";
|
|
7
|
+
import EmergencyRedirectsPage from "@/app/updates/emergency-redirects/page";
|
|
8
|
+
import UpdatePolicyEditor from "@/src/client/update-policy-editor";
|
|
9
|
+
import LoginPage from "@/app/login/page";
|
|
10
|
+
import { LocaleProvider, useI18n } from "./provider";
|
|
11
|
+
import { useFormatters } from "./use-formatters";
|
|
12
|
+
import { LOCALE_COOKIE, resolveLocale, type Locale } from "./messages";
|
|
13
|
+
|
|
14
|
+
const api = vi.hoisted(() => ({
|
|
15
|
+
getEmergencyRedirects: vi.fn(),
|
|
16
|
+
getAdminSession: vi.fn(),
|
|
17
|
+
createEmergencyRedirect: vi.fn(),
|
|
18
|
+
updateEmergencyRedirect: vi.fn(),
|
|
19
|
+
deleteEmergencyRedirect: vi.fn(),
|
|
20
|
+
getUpdatePolicy: vi.fn(),
|
|
21
|
+
getGuardActions: vi.fn(),
|
|
22
|
+
putUpdatePolicy: vi.fn(),
|
|
23
|
+
createGuardAction: vi.fn(),
|
|
24
|
+
deleteGuardAction: vi.fn(),
|
|
25
|
+
adminLogin: vi.fn(),
|
|
26
|
+
}));
|
|
27
|
+
vi.mock("@/src/client/admin-api", () => api);
|
|
28
|
+
vi.mock("next/navigation", () => ({
|
|
29
|
+
useRouter: () => ({ replace: vi.fn() }),
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
let root: Root;
|
|
33
|
+
let container: HTMLDivElement;
|
|
34
|
+
const redirect = {
|
|
35
|
+
id: "rule-1",
|
|
36
|
+
name: "Мой канал / $&",
|
|
37
|
+
enabled: true,
|
|
38
|
+
embeddedUpdateId: "11111111-1111-4111-8111-111111111111",
|
|
39
|
+
runtimeVersion: "1.0.0",
|
|
40
|
+
platform: "android",
|
|
41
|
+
fromChannel: "development",
|
|
42
|
+
toChannel: "production",
|
|
43
|
+
targetMode: "pinned",
|
|
44
|
+
expectedUpdateId: "22222222-2222-4222-8222-222222222222",
|
|
45
|
+
};
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
|
48
|
+
container = document.createElement("div");
|
|
49
|
+
document.body.append(container);
|
|
50
|
+
root = createRoot(container);
|
|
51
|
+
document.cookie = `${LOCALE_COOKIE}=; Path=/; Max-Age=0`;
|
|
52
|
+
api.getEmergencyRedirects.mockResolvedValue({ items: [redirect] });
|
|
53
|
+
api.getAdminSession.mockResolvedValue({ role: "admin" });
|
|
54
|
+
api.updateEmergencyRedirect.mockResolvedValue(redirect);
|
|
55
|
+
api.getUpdatePolicy.mockResolvedValue({
|
|
56
|
+
delivery: "manual",
|
|
57
|
+
guard: null,
|
|
58
|
+
policyVersion: 1,
|
|
59
|
+
editable: true,
|
|
60
|
+
publishedAt: null,
|
|
61
|
+
});
|
|
62
|
+
api.getGuardActions.mockResolvedValue({ items: [], canWrite: true });
|
|
63
|
+
vi.spyOn(window, "scrollTo").mockImplementation(() => {});
|
|
64
|
+
});
|
|
65
|
+
afterEach(async () => {
|
|
66
|
+
await act(async () => root.unmount());
|
|
67
|
+
container.remove();
|
|
68
|
+
vi.restoreAllMocks();
|
|
69
|
+
vi.clearAllMocks();
|
|
70
|
+
});
|
|
71
|
+
async function switchTo(locale: Locale) {
|
|
72
|
+
const select = container.querySelector<HTMLSelectElement>(
|
|
73
|
+
"select[aria-label]",
|
|
74
|
+
)!;
|
|
75
|
+
await act(async () => {
|
|
76
|
+
select.value = locale;
|
|
77
|
+
select.dispatchEvent(new Event("change", { bubbles: true }));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
async function click(text: string) {
|
|
81
|
+
const button = [...container.querySelectorAll("button")].find(
|
|
82
|
+
(b) => b.textContent === text,
|
|
83
|
+
);
|
|
84
|
+
expect(button, text).toBeDefined();
|
|
85
|
+
await act(async () => button!.click());
|
|
86
|
+
}
|
|
87
|
+
function Formats() {
|
|
88
|
+
const { formatLocale } = useI18n();
|
|
89
|
+
const { number, fullDate } = useFormatters();
|
|
90
|
+
return (
|
|
91
|
+
<output data-locale={formatLocale}>
|
|
92
|
+
{number(12345.6)} | {fullDate("2026-10-26T12:34:00Z")}
|
|
93
|
+
</output>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
describe("language switching", () => {
|
|
98
|
+
it("switches recovery forms, status, notices and accessibility labels without losing data", async () => {
|
|
99
|
+
await act(async () =>
|
|
100
|
+
root.render(
|
|
101
|
+
<LocaleProvider initialLocale="en">
|
|
102
|
+
<LanguageSwitcher />
|
|
103
|
+
<EmergencyRedirectsPage />
|
|
104
|
+
</LocaleProvider>,
|
|
105
|
+
),
|
|
106
|
+
);
|
|
107
|
+
expect(container.textContent).toContain("Emergency redirects");
|
|
108
|
+
await click("Edit");
|
|
109
|
+
await switchTo("ru");
|
|
110
|
+
expect(container.textContent).toContain("Исходный канал");
|
|
111
|
+
expect(container.textContent).toContain("Закреплённое обновление");
|
|
112
|
+
expect(
|
|
113
|
+
container
|
|
114
|
+
.querySelector("select[aria-label]")
|
|
115
|
+
?.getAttribute("aria-label"),
|
|
116
|
+
).toBe("Язык интерфейса");
|
|
117
|
+
expect(
|
|
118
|
+
[...container.querySelectorAll("input")].map((i) => i.value),
|
|
119
|
+
).toContain(redirect.name);
|
|
120
|
+
await click("Сохранить изменения");
|
|
121
|
+
expect(api.updateEmergencyRedirect).toHaveBeenCalledWith(
|
|
122
|
+
"rule-1",
|
|
123
|
+
expect.objectContaining({
|
|
124
|
+
name: redirect.name,
|
|
125
|
+
fromChannel: "development",
|
|
126
|
+
toChannel: "production",
|
|
127
|
+
targetMode: "pinned",
|
|
128
|
+
}),
|
|
129
|
+
);
|
|
130
|
+
expect(container.textContent).toContain("Аварийный маршрут обновлён");
|
|
131
|
+
await switchTo("uk");
|
|
132
|
+
expect(container.textContent).toContain("Аварійний маршрут оновлено");
|
|
133
|
+
expect(container.textContent).toContain("Початковий канал");
|
|
134
|
+
expect(container.textContent).toContain("Увімкнено");
|
|
135
|
+
expect(container.textContent).toContain(redirect.name);
|
|
136
|
+
expect(document.documentElement.lang).toBe("uk");
|
|
137
|
+
expect(document.cookie).toContain(`${LOCALE_COOKIE}=uk`);
|
|
138
|
+
expect(api.getEmergencyRedirects).toHaveBeenCalledTimes(2);
|
|
139
|
+
await switchTo("en");
|
|
140
|
+
expect(container.textContent).toContain("Emergency redirect updated");
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("localizes recovery validation errors and read-only actions", async () => {
|
|
144
|
+
api.getAdminSession.mockResolvedValue({ role: "viewer" });
|
|
145
|
+
await act(async () =>
|
|
146
|
+
root.render(
|
|
147
|
+
<LocaleProvider initialLocale="uk">
|
|
148
|
+
<LanguageSwitcher />
|
|
149
|
+
<EmergencyRedirectsPage />
|
|
150
|
+
</LocaleProvider>,
|
|
151
|
+
),
|
|
152
|
+
);
|
|
153
|
+
expect(container.textContent).toContain("Лише читання");
|
|
154
|
+
expect(container.querySelector("form")).toBeNull();
|
|
155
|
+
expect(container.textContent).not.toContain("Read only");
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("renders login and formatting in the saved locale on remount and on the server", async () => {
|
|
159
|
+
await act(async () =>
|
|
160
|
+
root.render(
|
|
161
|
+
<LocaleProvider initialLocale="en">
|
|
162
|
+
<LanguageSwitcher />
|
|
163
|
+
<Formats />
|
|
164
|
+
</LocaleProvider>,
|
|
165
|
+
),
|
|
166
|
+
);
|
|
167
|
+
await switchTo("uk");
|
|
168
|
+
expect(container.querySelector("output")?.dataset.locale).toBe("uk-UA");
|
|
169
|
+
expect(container.querySelector("output")?.textContent).toContain(
|
|
170
|
+
new Intl.NumberFormat("uk-UA").format(12345.6),
|
|
171
|
+
);
|
|
172
|
+
expect(container.querySelector("output")?.textContent).toContain(
|
|
173
|
+
new Intl.DateTimeFormat("uk-UA", {
|
|
174
|
+
dateStyle: "medium",
|
|
175
|
+
timeStyle: "short",
|
|
176
|
+
timeZone: "UTC",
|
|
177
|
+
}).format(new Date("2026-10-26T12:34:00Z")),
|
|
178
|
+
);
|
|
179
|
+
const saved = resolveLocale(document.cookie.split("=")[1]);
|
|
180
|
+
await act(async () =>
|
|
181
|
+
root.render(
|
|
182
|
+
<LocaleProvider key="reload" initialLocale={saved}>
|
|
183
|
+
<LoginPage />
|
|
184
|
+
</LocaleProvider>,
|
|
185
|
+
),
|
|
186
|
+
);
|
|
187
|
+
expect(container.textContent).toContain("Увійти");
|
|
188
|
+
expect(container.querySelector("select")?.value).toBe("uk");
|
|
189
|
+
const html = renderToString(
|
|
190
|
+
<LocaleProvider initialLocale={saved}>
|
|
191
|
+
<LanguageSwitcher />
|
|
192
|
+
</LocaleProvider>,
|
|
193
|
+
);
|
|
194
|
+
expect(html).toContain('aria-label="Мова інтерфейсу"');
|
|
195
|
+
expect(html).toContain('value="uk" lang="uk" selected=""');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("switches the policy editor, catalog, and errors in place", async () => {
|
|
199
|
+
await act(async () =>
|
|
200
|
+
root.render(
|
|
201
|
+
<LocaleProvider initialLocale="ru">
|
|
202
|
+
<LanguageSwitcher />
|
|
203
|
+
<UpdatePolicyEditor encodedKey="test" onSaved={async () => {}} />
|
|
204
|
+
</LocaleProvider>,
|
|
205
|
+
),
|
|
206
|
+
);
|
|
207
|
+
expect(container.textContent).toContain("Политика обновления");
|
|
208
|
+
expect(container.textContent).toContain("Каталог действий");
|
|
209
|
+
await switchTo("uk");
|
|
210
|
+
expect(container.textContent).toContain("Політика оновлення");
|
|
211
|
+
expect(container.textContent).toContain("Додати дію до каталогу");
|
|
212
|
+
api.putUpdatePolicy.mockRejectedValue(
|
|
213
|
+
new Error("Update policy is immutable after publication."),
|
|
214
|
+
);
|
|
215
|
+
await click("Зберегти політику");
|
|
216
|
+
expect(container.textContent).toContain(
|
|
217
|
+
"Політику оновлення не можна змінити після публікації.",
|
|
218
|
+
);
|
|
219
|
+
await switchTo("ru");
|
|
220
|
+
expect(container.textContent).toContain(
|
|
221
|
+
"Политику обновления нельзя изменить после публикации.",
|
|
222
|
+
);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
@@ -1,40 +1,123 @@
|
|
|
1
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import ts from "typescript";
|
|
1
4
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { createTranslator, resolveLocale } from "./messages";
|
|
5
|
+
import { createTranslator, resolveLocale, type Locale } from "./messages";
|
|
3
6
|
import english from "./en.json";
|
|
7
|
+
import russian from "./ru.json";
|
|
8
|
+
import ukrainian from "./uk.json";
|
|
9
|
+
|
|
10
|
+
const catalogs = { en: english, ru: russian, uk: ukrainian };
|
|
4
11
|
|
|
5
12
|
describe("admin interface language", () => {
|
|
6
|
-
it("
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
it("resolves supported preferences and keeps English as the default", () => {
|
|
14
|
+
for (const locale of ["en", "ru", "uk"]) {
|
|
15
|
+
expect(resolveLocale(locale)).toBe(locale);
|
|
16
|
+
}
|
|
17
|
+
for (const locale of [undefined, "ua", "de", "constructor"]) {
|
|
18
|
+
expect(resolveLocale(locale)).toBe("en");
|
|
19
|
+
}
|
|
11
20
|
});
|
|
12
|
-
|
|
21
|
+
|
|
22
|
+
it("translates labels and English API errors without translating user data", () => {
|
|
13
23
|
expect(createTranslator("en")("Установки")).toBe("Installations");
|
|
14
24
|
expect(createTranslator("ru")("Установки")).toBe("Установки");
|
|
25
|
+
expect(createTranslator("uk")("Установки")).toBe("Встановлення");
|
|
15
26
|
expect(createTranslator("ru")("Invalid credentials")).toBe(
|
|
16
27
|
"Неверные учётные данные",
|
|
17
28
|
);
|
|
29
|
+
expect(createTranslator("uk")("Invalid credentials")).toBe(
|
|
30
|
+
"Неправильні облікові дані",
|
|
31
|
+
);
|
|
32
|
+
expect(
|
|
33
|
+
createTranslator("uk")("fromChannel and toChannel must differ"),
|
|
34
|
+
).toBe("Початковий і цільовий канали мають відрізнятися");
|
|
18
35
|
expect(
|
|
19
|
-
createTranslator("
|
|
20
|
-
).toBe("
|
|
36
|
+
createTranslator("uk")("Канал {0}, {1}", ["Мой канал", "android"]),
|
|
37
|
+
).toBe("Канал Мой канал, android");
|
|
21
38
|
expect(createTranslator("en")("Скопировать {0}", ["$& <script>"])).toBe(
|
|
22
39
|
"Copy $& <script>",
|
|
23
40
|
);
|
|
24
41
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
42
|
+
|
|
43
|
+
it("can render an existing notification in another language", () => {
|
|
44
|
+
const notice = { key: "Policy saved as version {0}.", values: [3] };
|
|
45
|
+
expect(createTranslator("en")(notice)).toBe(
|
|
46
|
+
"Policy saved as version 3.",
|
|
47
|
+
);
|
|
48
|
+
expect(createTranslator("ru")(notice)).toBe(
|
|
49
|
+
"Политика сохранена как версия 3.",
|
|
50
|
+
);
|
|
51
|
+
expect(createTranslator("uk")(notice)).toBe(
|
|
52
|
+
"Політику збережено як версію 3.",
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it.each(Object.keys(catalogs) as Locale[])(
|
|
57
|
+
"keeps %s complete with matching interpolation slots",
|
|
58
|
+
(locale) => {
|
|
59
|
+
const slots = (s: string) =>
|
|
60
|
+
[...s.matchAll(/\{\d+\}/g)].map(([value]) => value).sort();
|
|
61
|
+
expect(Object.keys(catalogs[locale]).sort()).toEqual(
|
|
62
|
+
Object.keys(english).sort(),
|
|
63
|
+
);
|
|
64
|
+
for (const [source, translated] of Object.entries(catalogs[locale])) {
|
|
65
|
+
expect(translated.trim(), source).not.toBe("");
|
|
66
|
+
expect(slots(translated), source).toEqual(slots(source));
|
|
67
|
+
if (locale === "en")
|
|
68
|
+
expect(translated, source).not.toMatch(/[А-Яа-яЁёІіЇїЄєҐґ]/);
|
|
69
|
+
if (locale === "uk")
|
|
70
|
+
expect(translated, source).not.toMatch(/[ыэъёЫЭЪЁ]/);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
it("has translations for every literal UI translation key", () => {
|
|
76
|
+
function files(directory: string): string[] {
|
|
77
|
+
return readdirSync(directory, { withFileTypes: true }).flatMap(
|
|
78
|
+
(entry) => {
|
|
79
|
+
const path = join(directory, entry.name);
|
|
80
|
+
return entry.isDirectory()
|
|
81
|
+
? files(path)
|
|
82
|
+
: /\.tsx?$/.test(path) && !path.includes(".test.")
|
|
83
|
+
? [path]
|
|
84
|
+
: [];
|
|
85
|
+
},
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
const keys = new Set([
|
|
89
|
+
...Object.keys(english),
|
|
90
|
+
...Object.values(english),
|
|
91
|
+
]);
|
|
92
|
+
for (const path of ["app", "components", "src/client"].flatMap(files)) {
|
|
93
|
+
const source = ts.createSourceFile(
|
|
94
|
+
path,
|
|
95
|
+
readFileSync(path, "utf8"),
|
|
96
|
+
ts.ScriptTarget.Latest,
|
|
97
|
+
true,
|
|
98
|
+
);
|
|
99
|
+
function visit(node: ts.Node) {
|
|
100
|
+
if (
|
|
101
|
+
ts.isCallExpression(node) &&
|
|
102
|
+
node.expression.getText(source) === "t"
|
|
103
|
+
) {
|
|
104
|
+
const key = node.arguments[0];
|
|
105
|
+
if (key && ts.isStringLiteral(key))
|
|
106
|
+
expect(keys.has(key.text), `${path}: ${key.text}`).toBe(true);
|
|
107
|
+
}
|
|
108
|
+
ts.forEachChild(node, visit);
|
|
109
|
+
}
|
|
110
|
+
visit(source);
|
|
32
111
|
}
|
|
33
112
|
});
|
|
113
|
+
|
|
34
114
|
it("preserves unknown technical errors and incomplete placeholders", () => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
115
|
+
for (const locale of Object.keys(catalogs) as Locale[]) {
|
|
116
|
+
const t = createTranslator(locale);
|
|
117
|
+
expect(t("HTTP 503")).toBe("HTTP 503");
|
|
118
|
+
expect(t("constructor")).toBe("constructor");
|
|
119
|
+
expect(t("toString")).toBe("toString");
|
|
120
|
+
}
|
|
38
121
|
expect(createTranslator("en")("Канал {0}, {1}", ["preview"])).toBe(
|
|
39
122
|
"Channel preview, {1}",
|
|
40
123
|
);
|
|
@@ -1,31 +1,46 @@
|
|
|
1
1
|
import english from "./en.json";
|
|
2
|
+
import russian from "./ru.json";
|
|
3
|
+
import ukrainian from "./uk.json";
|
|
2
4
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
Object.entries(
|
|
5
|
+
const catalogs = {
|
|
6
|
+
en: new Map(Object.entries(english)),
|
|
7
|
+
ru: new Map(Object.entries(russian)),
|
|
8
|
+
uk: new Map(Object.entries(ukrainian)),
|
|
9
|
+
};
|
|
10
|
+
// Also accept English API errors and labels from the original interface.
|
|
11
|
+
const keysByEnglish = new Map(
|
|
12
|
+
Object.entries(english).map(([key, translated]) => [translated, key]),
|
|
6
13
|
);
|
|
7
14
|
|
|
8
|
-
export type Locale = "en" | "ru";
|
|
15
|
+
export type Locale = "en" | "ru" | "uk";
|
|
16
|
+
export const formatLocales: Record<Locale, string> = {
|
|
17
|
+
en: "en-US",
|
|
18
|
+
ru: "ru-RU",
|
|
19
|
+
uk: "uk-UA",
|
|
20
|
+
};
|
|
21
|
+
type TranslationValues = readonly (string | number | null | undefined)[];
|
|
22
|
+
export type TranslationMessage =
|
|
23
|
+
string | { key: string; values?: TranslationValues };
|
|
9
24
|
export const LOCALE_COOKIE = "ota-locale";
|
|
10
25
|
export const defaultLocale: Locale = "en";
|
|
11
26
|
export function resolveLocale(value: string | undefined): Locale {
|
|
12
|
-
return value === "ru"
|
|
27
|
+
return value === "ru" || value === "uk" ? value : defaultLocale;
|
|
13
28
|
}
|
|
14
29
|
|
|
15
|
-
/**
|
|
30
|
+
/** Translate at render time so existing notices follow language changes too. */
|
|
16
31
|
export function createTranslator(locale: Locale) {
|
|
17
|
-
return (
|
|
18
|
-
message:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
32
|
+
return (message: TranslationMessage, values: TranslationValues = []) => {
|
|
33
|
+
const source = typeof message === "string" ? message : message.key;
|
|
34
|
+
const replacements =
|
|
35
|
+
typeof message === "string" ? values : (message.values ?? []);
|
|
36
|
+
const key = catalogs.en.has(source)
|
|
37
|
+
? source
|
|
38
|
+
: (keysByEnglish.get(source) ?? source);
|
|
39
|
+
const translated = catalogs[locale].get(key) ?? source;
|
|
25
40
|
return translated.replace(/\{(\d+)\}/g, (placeholder, index) =>
|
|
26
|
-
|
|
41
|
+
replacements[Number(index)] === undefined
|
|
27
42
|
? placeholder
|
|
28
|
-
: String(
|
|
43
|
+
: String(replacements[Number(index)]),
|
|
29
44
|
);
|
|
30
45
|
};
|
|
31
46
|
}
|