@jskit-ai/realtime 0.1.248 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 - 2026-10-29
4
+
5
+ - Translation ready: every user-visible text is a message key with its English in `locales/en.json`, so an app translates it by supplying translation files only. With no translations, texts and behaviour are unchanged. See the guide "Translating a JSKIT app".
6
+
7
+ ### New message keys (6)
8
+
9
+ All keys in `locales/en.json` (exported as `./locales/en.json`) are new in this version.
10
+
11
+ <details><summary>Key list</summary>
12
+
13
+ - `jskit.realtime.indicator.connected`
14
+ - `jskit.realtime.indicator.connectedTooltip`
15
+ - `jskit.realtime.indicator.disconnected`
16
+ - `jskit.realtime.indicator.disconnectedTooltip`
17
+ - `jskit.realtime.indicator.reconnect`
18
+ - `jskit.realtime.indicator.unavailableTooltip`
19
+
20
+ </details>
@@ -0,0 +1,14 @@
1
+ {
2
+ "jskit": {
3
+ "realtime": {
4
+ "indicator": {
5
+ "connected": "Realtime connected",
6
+ "connectedTooltip": "Realtime is connected. Live updates are active.",
7
+ "disconnected": "Realtime disconnected",
8
+ "disconnectedTooltip": "Live updates are disconnected. Click to reconnect. If your session expired, sign in again.",
9
+ "reconnect": "Reconnect live updates",
10
+ "unavailableTooltip": "Realtime is unavailable. Live updates are disabled for this page."
11
+ }
12
+ }
13
+ }
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/realtime",
3
- "version": "0.1.248",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test --test-concurrency=1"
@@ -11,7 +11,8 @@
11
11
  "./client": "./src/client/RealtimeClientProvider.js",
12
12
  "./client/RealtimeClientProvider": "./src/client/RealtimeClientProvider.js",
13
13
  "./client/composables/useRealtimeEvent": "./src/client/composables/useRealtimeEvent.js",
14
- "./client/runtime": "./src/client/runtime.js"
14
+ "./client/runtime": "./src/client/runtime.js",
15
+ "./locales/en.json": "./locales/en.json"
15
16
  },
16
17
  "dependencies": {
17
18
  "@socket.io/redis-adapter": "^8.3.0",
@@ -20,7 +21,7 @@
20
21
  "socket.io-client": "^4.8.3"
21
22
  },
22
23
  "peerDependencies": {
23
- "@jskit-ai/kernel": "0.1.248",
24
+ "@jskit-ai/kernel": "0.2.0",
24
25
  "vue": "^3.5.13"
25
26
  },
26
27
  "description": "Thin, generic realtime runtime wrappers for socket.io server and client.",
@@ -91,6 +92,10 @@
91
92
  {
92
93
  "subpath": "./client/runtime",
93
94
  "summary": "Exports createSocketIoClient, disconnectSocketIoClient and reconnectSocketIoClient."
95
+ },
96
+ {
97
+ "subpath": "./locales/en.json",
98
+ "summary": "English catalog for the realtime connection indicator, registered by the generated client bootstrap."
94
99
  }
95
100
  ],
96
101
  "capabilities": {
@@ -2,7 +2,7 @@
2
2
  "private": true,
3
3
  "type": "module",
4
4
  "dependencies": {
5
- "@jskit-ai/realtime": "0.1.248",
6
- "@jskit-ai/shell-web": "0.1.255"
5
+ "@jskit-ai/realtime": "0.2.0",
6
+ "@jskit-ai/shell-web": "0.2.0"
7
7
  }
8
8
  }
@@ -1,6 +1,9 @@
1
1
  import { computed, defineComponent, h, onBeforeUnmount, onMounted, ref } from "vue";
2
2
  import { EMPTY_REALTIME_SOCKET, useRealtimeSocket } from "../composables/useRealtimeEvent.js";
3
3
  import { reconnectSocketIoClient } from "../runtime.js";
4
+ import { useJskitText } from "../i18n.js";
5
+
6
+ const { t } = useJskitText();
4
7
 
5
8
  const ROOT_STYLE = Object.freeze({
6
9
  alignItems: "center",
@@ -37,12 +40,12 @@ const SR_ONLY_STYLE = Object.freeze({
37
40
 
38
41
  function resolveTooltipText({ realtimeAvailable, connected }) {
39
42
  if (!realtimeAvailable) {
40
- return "Realtime is unavailable. Live updates are disabled for this page.";
43
+ return t("jskit.realtime.indicator.unavailableTooltip");
41
44
  }
42
45
  if (connected) {
43
- return "Realtime is connected. Live updates are active.";
46
+ return t("jskit.realtime.indicator.connectedTooltip");
44
47
  }
45
- return "Live updates are disconnected. Click to reconnect. If your session expired, sign in again.";
48
+ return t("jskit.realtime.indicator.disconnectedTooltip");
46
49
  }
47
50
 
48
51
  const RealtimeConnectionIndicator = defineComponent({
@@ -60,7 +63,9 @@ const RealtimeConnectionIndicator = defineComponent({
60
63
  });
61
64
  });
62
65
 
63
- const statusLabel = computed(() => (connected.value ? "Realtime connected" : "Realtime disconnected"));
66
+ const statusLabel = computed(() =>
67
+ connected.value ? t("jskit.realtime.indicator.connected") : t("jskit.realtime.indicator.disconnected")
68
+ );
64
69
 
65
70
  const dotStyle = computed(() => ({
66
71
  ...DOT_STYLE,
@@ -116,7 +121,9 @@ const RealtimeConnectionIndicator = defineComponent({
116
121
  style: { ...ROOT_STYLE, cursor: realtimeAvailable && !connected.value ? "pointer" : "default" },
117
122
  title: tooltipText.value,
118
123
  type: "button",
119
- "aria-label": realtimeAvailable && !connected.value ? "Reconnect live updates" : statusLabel.value
124
+ "aria-label": realtimeAvailable && !connected.value
125
+ ? t("jskit.realtime.indicator.reconnect")
126
+ : statusLabel.value
120
127
  },
121
128
  [
122
129
  h("span", { style: dotStyle.value, "aria-hidden": "true" }),
@@ -0,0 +1,8 @@
1
+ import { registerJskitMessages, useJskitText } from "@jskit-ai/kernel/client/i18n";
2
+ import en from "../../locales/en.json" with { type: "json" };
3
+
4
+ // realtime's English, registered on import so its indicator translates in
5
+ // fixtures and tests as well as in a bootstrapped app.
6
+ registerJskitMessages(en);
7
+
8
+ export { useJskitText };
@@ -33,6 +33,11 @@ function debugEnabled(config, env) {
33
33
  return parseDebugFlag(env?.JSKIT_REALTIME_DEBUG, parseDebugFlag(config?.realtime?.debug, false));
34
34
  }
35
35
 
36
+ // The kernel's code for this English, so a client can show it in the user's language.
37
+ function authenticationRequiredError() {
38
+ return Object.assign(new Error("Authentication required."), { statusCode: 401, code: "AUTHENTICATION_REQUIRED" });
39
+ }
40
+
36
41
  function createRealtimeCapability({ io }) {
37
42
  const capability = Object.freeze({
38
43
  onConnection(listener) {
@@ -49,7 +54,7 @@ function createRealtimeCapability({ io }) {
49
54
  socket, request, authService: state.authService, audiences: state.audiences
50
55
  });
51
56
  if (!socket.connected || (!actor && realtimeAuthenticationRequired(state.authService))) {
52
- throw Object.assign(new Error("Authentication required."), { statusCode: 401 });
57
+ throw authenticationRequiredError();
53
58
  }
54
59
  if (actor) request.user = actor;
55
60
  return request;
@@ -70,7 +75,7 @@ function createRealtimeCapability({ io }) {
70
75
  readRequest,
71
76
  async authenticate() {
72
77
  const request = await readRequest();
73
- if (!request.user) throw Object.assign(new Error("Authentication required."), { statusCode: 401 });
78
+ if (!request.user) throw authenticationRequiredError();
74
79
  return request;
75
80
  }
76
81
  });
@@ -0,0 +1,18 @@
1
+ import assert from "node:assert/strict";
2
+ import path from "node:path";
3
+ import test from "node:test";
4
+ import { fileURLToPath } from "node:url";
5
+ import { evaluateI18nCatalogContract } from "../../../tooling/test-support/i18nCatalogContract.mjs";
6
+
7
+ const TEST_DIRECTORY = path.dirname(fileURLToPath(import.meta.url));
8
+ const REPO_ROOT = path.resolve(TEST_DIRECTORY, "..", "..", "..");
9
+
10
+ test("realtime English catalog matches its source", () => {
11
+ const { problems } = evaluateI18nCatalogContract({
12
+ repoRoot: REPO_ROOT,
13
+ packageDir: path.join(REPO_ROOT, "packages", "realtime"),
14
+ // The client socket's injection key shares the jskit.realtime prefix but is not a message key.
15
+ nonMessageLiterals: ["jskit.realtime.runtime.client.socket"]
16
+ });
17
+ assert.deepEqual(problems, []);
18
+ });
@@ -0,0 +1,41 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { createSSRApp, h } from "vue";
4
+ import { renderToString } from "vue/server-renderer";
5
+ import { createI18n } from "vue-i18n";
6
+ import { setJskitI18n } from "@jskit-ai/kernel/client/i18n";
7
+ import { RealtimeConnectionIndicator } from "../src/client/components/RealtimeConnectionIndicator.js";
8
+
9
+ function renderIndicator() {
10
+ return renderToString(createSSRApp({ render: () => h(RealtimeConnectionIndicator) }));
11
+ }
12
+
13
+ test("realtime indicator texts are English by default and follow the app's language", async () => {
14
+ const english = await renderIndicator();
15
+ assert.match(english, /title="Realtime is unavailable\. Live updates are disabled for this page\."/u);
16
+ assert.match(english, />Realtime disconnected</u);
17
+
18
+ setJskitI18n(createI18n({
19
+ legacy: false,
20
+ locale: "xx",
21
+ messages: {
22
+ xx: {
23
+ jskit: {
24
+ realtime: {
25
+ indicator: {
26
+ unavailableTooltip: "[xx] Temps réel indisponible.",
27
+ disconnected: "[xx] Déconnecté"
28
+ }
29
+ }
30
+ }
31
+ }
32
+ }
33
+ }));
34
+ try {
35
+ const translated = await renderIndicator();
36
+ assert.match(translated, /title="\[xx\] Temps réel indisponible\."/u);
37
+ assert.match(translated, />\[xx\] Déconnecté</u);
38
+ } finally {
39
+ setJskitI18n(null);
40
+ }
41
+ });