@jskit-ai/mobile-capacitor 0.1.186 → 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,26 @@
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 (12)
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.mobile.apiRequest.apiBaseUrlInvalid`
14
+ - `jskit.mobile.apiRequest.apiBaseUrlProtocol`
15
+ - `jskit.mobile.apiRequest.apiBaseUrlRequired`
16
+ - `jskit.mobile.apiRequest.apiBaseUrlRequiredForRequests`
17
+ - `jskit.mobile.apiRequest.urlProtocol`
18
+ - `jskit.mobile.apiRequest.urlRequired`
19
+ - `jskit.mobile.apiRequest.requestUrlProtocol`
20
+ - `jskit.mobile.apiRequest.requestUrlRequired`
21
+ - `jskit.mobile.oauth.apiBaseUrlRequired`
22
+ - `jskit.mobile.oauth.browserUnavailable`
23
+ - `jskit.mobile.oauth.urlProtocol`
24
+ - `jskit.mobile.oauth.urlRequired`
25
+
26
+ </details>
@@ -0,0 +1,22 @@
1
+ {
2
+ "jskit": {
3
+ "mobile": {
4
+ "apiRequest": {
5
+ "apiBaseUrlInvalid": "config.mobile.apiBaseUrl must be a valid absolute URL.",
6
+ "apiBaseUrlProtocol": "config.mobile.apiBaseUrl must use http or https.",
7
+ "apiBaseUrlRequired": "config.mobile.apiBaseUrl is required.",
8
+ "apiBaseUrlRequiredForRequests": "config.mobile.apiBaseUrl is required for Capacitor API requests.",
9
+ "urlProtocol": "URL must use http or https.",
10
+ "urlRequired": "URL is required.",
11
+ "requestUrlProtocol": "Capacitor API request URL must use http or https.",
12
+ "requestUrlRequired": "Capacitor API request URL is required."
13
+ },
14
+ "oauth": {
15
+ "apiBaseUrlRequired": "config.mobile.apiBaseUrl is required to launch OAuth from the Capacitor shell.",
16
+ "browserUnavailable": "Browser location.assign() is unavailable for OAuth launch.",
17
+ "urlProtocol": "OAuth launch URL must use http or https.",
18
+ "urlRequired": "OAuth launch URL is required."
19
+ }
20
+ }
21
+ }
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/mobile-capacitor",
3
- "version": "0.1.186",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test --test-concurrency=1"
@@ -8,7 +8,8 @@
8
8
  "exports": {
9
9
  "./client": "./src/client/index.js",
10
10
  "./client/runtime/mobileCapacitorRuntime": "./src/client/runtime/mobileCapacitorRuntime.js",
11
- "./client/runtime/globalCapacitorAppAdapter": "./src/client/runtime/globalCapacitorAppAdapter.js"
11
+ "./client/runtime/globalCapacitorAppAdapter": "./src/client/runtime/globalCapacitorAppAdapter.js",
12
+ "./locales/en.json": "./locales/en.json"
12
13
  },
13
14
  "dependencies": {
14
15
  "@capacitor/browser": "^8.0.5",
@@ -59,7 +60,7 @@
59
60
  }
60
61
  },
61
62
  "peerDependencies": {
62
- "@jskit-ai/kernel": "0.1.248",
63
- "@jskit-ai/shell-web": "0.1.255"
63
+ "@jskit-ai/kernel": "0.2.0",
64
+ "@jskit-ai/shell-web": "0.2.0"
64
65
  }
65
66
  }
@@ -0,0 +1,8 @@
1
+ import { createTextError, registerJskitMessages, useJskitText } from "@jskit-ai/kernel/client/i18n";
2
+ import en from "../../locales/en.json" with { type: "json" };
3
+
4
+ // mobile-capacitor's English, registered on import so its errors render in the
5
+ // user's language wherever the app shows them.
6
+ registerJskitMessages(en);
7
+
8
+ export { createTextError, useJskitText };
@@ -1,19 +1,22 @@
1
+ import { createTextError } from "../i18n.js";
2
+
1
3
  const API_ROUTE_PREFIXES = Object.freeze([
2
4
  "/api",
3
5
  "/socket.io"
4
6
  ]);
5
7
 
8
+ // Each message is one of this package's message keys or a caller's own text.
6
9
  function parseAbsoluteHttpUrl(url = "", {
7
10
  apiBaseUrl = "",
8
- emptyUrlMessage = "URL is required.",
9
- missingApiBaseUrlMessage = "config.mobile.apiBaseUrl is required.",
10
- invalidApiBaseUrlMessage = "config.mobile.apiBaseUrl must be a valid absolute URL.",
11
- invalidApiBaseUrlProtocolMessage = "config.mobile.apiBaseUrl must use http or https.",
12
- invalidUrlProtocolMessage = "URL must use http or https."
11
+ emptyUrlMessage = "jskit.mobile.apiRequest.urlRequired",
12
+ missingApiBaseUrlMessage = "jskit.mobile.apiRequest.apiBaseUrlRequired",
13
+ invalidApiBaseUrlMessage = "jskit.mobile.apiRequest.apiBaseUrlInvalid",
14
+ invalidApiBaseUrlProtocolMessage = "jskit.mobile.apiRequest.apiBaseUrlProtocol",
15
+ invalidUrlProtocolMessage = "jskit.mobile.apiRequest.urlProtocol"
13
16
  } = {}) {
14
17
  const normalizedUrl = String(url || "").trim();
15
18
  if (!normalizedUrl) {
16
- throw new Error(emptyUrlMessage);
19
+ throw createTextError(emptyUrlMessage);
17
20
  }
18
21
 
19
22
  let absoluteUrl = null;
@@ -24,26 +27,26 @@ function parseAbsoluteHttpUrl(url = "", {
24
27
  if (absoluteUrl) {
25
28
  const protocol = String(absoluteUrl.protocol || "").toLowerCase();
26
29
  if (protocol !== "http:" && protocol !== "https:") {
27
- throw new Error(invalidUrlProtocolMessage);
30
+ throw createTextError(invalidUrlProtocolMessage);
28
31
  }
29
32
  return absoluteUrl.toString();
30
33
  }
31
34
 
32
35
  const normalizedApiBaseUrl = String(apiBaseUrl || "").trim();
33
36
  if (!normalizedApiBaseUrl) {
34
- throw new Error(missingApiBaseUrlMessage);
37
+ throw createTextError(missingApiBaseUrlMessage);
35
38
  }
36
39
 
37
40
  let baseUrl;
38
41
  try {
39
42
  baseUrl = new URL(normalizedApiBaseUrl);
40
43
  } catch {
41
- throw new Error(invalidApiBaseUrlMessage);
44
+ throw createTextError(invalidApiBaseUrlMessage);
42
45
  }
43
46
 
44
47
  const baseProtocol = String(baseUrl.protocol || "").toLowerCase();
45
48
  if (baseProtocol !== "http:" && baseProtocol !== "https:") {
46
- throw new Error(invalidApiBaseUrlProtocolMessage);
49
+ throw createTextError(invalidApiBaseUrlProtocolMessage);
47
50
  }
48
51
 
49
52
  return new URL(normalizedUrl, baseUrl).toString();
@@ -120,9 +123,9 @@ function createCapacitorAwareFetch({
120
123
  }
121
124
 
122
125
  const resolvedUrl = resolveCapacitorAbsoluteHttpUrl(normalizedInput.rawUrl, apiBaseUrl, {
123
- emptyUrlMessage: "Capacitor API request URL is required.",
124
- missingApiBaseUrlMessage: "config.mobile.apiBaseUrl is required for Capacitor API requests.",
125
- invalidUrlProtocolMessage: "Capacitor API request URL must use http or https."
126
+ emptyUrlMessage: "jskit.mobile.apiRequest.requestUrlRequired",
127
+ missingApiBaseUrlMessage: "jskit.mobile.apiRequest.apiBaseUrlRequiredForRequests",
128
+ invalidUrlProtocolMessage: "jskit.mobile.apiRequest.requestUrlProtocol"
126
129
  });
127
130
 
128
131
  return fetchImpl(normalizedInput.rebuild(resolvedUrl), init);
@@ -1,11 +1,12 @@
1
1
  import { Browser } from "@capacitor/browser";
2
2
  import { resolveCapacitorAbsoluteHttpUrl } from "./apiRequestClient.js";
3
+ import { createTextError } from "../i18n.js";
3
4
 
4
5
  function resolveCapacitorLaunchUrl(url = "", apiBaseUrl = "") {
5
6
  return resolveCapacitorAbsoluteHttpUrl(url, apiBaseUrl, {
6
- emptyUrlMessage: "OAuth launch URL is required.",
7
- missingApiBaseUrlMessage: "config.mobile.apiBaseUrl is required to launch OAuth from the Capacitor shell.",
8
- invalidUrlProtocolMessage: "OAuth launch URL must use http or https."
7
+ emptyUrlMessage: "jskit.mobile.oauth.urlRequired",
8
+ missingApiBaseUrlMessage: "jskit.mobile.oauth.apiBaseUrlRequired",
9
+ invalidUrlProtocolMessage: "jskit.mobile.oauth.urlProtocol"
9
10
  });
10
11
  }
11
12
 
@@ -22,7 +23,7 @@ function createCapacitorAwareOAuthLaunchClient({
22
23
  async open({ url = "" } = {}) {
23
24
  const normalizedUrl = String(url || "").trim();
24
25
  if (!normalizedUrl) {
25
- throw new Error("OAuth launch URL is required.");
26
+ throw createTextError("jskit.mobile.oauth.urlRequired");
26
27
  }
27
28
 
28
29
  if (adapter?.available === true && browserPlugin && typeof browserPlugin.open === "function") {
@@ -33,7 +34,7 @@ function createCapacitorAwareOAuthLaunchClient({
33
34
  }
34
35
 
35
36
  if (!resolvedLocation || typeof resolvedLocation.assign !== "function") {
36
- throw new Error("Browser location.assign() is unavailable for OAuth launch.");
37
+ throw createTextError("jskit.mobile.oauth.browserUnavailable");
37
38
  }
38
39
 
39
40
  resolvedLocation.assign(normalizedUrl);
@@ -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("mobile-capacitor English catalog matches its source", () => {
11
+ const { problems } = evaluateI18nCatalogContract({
12
+ repoRoot: REPO_ROOT,
13
+ packageDir: path.join(REPO_ROOT, "packages", "mobile-capacitor"),
14
+ // The fetch-restore symbol shares the jskit.mobile prefix but is not a message key.
15
+ nonMessageLiterals: ["jskit.mobile.capacitor.restoreFetch"]
16
+ });
17
+ assert.deepEqual(problems, []);
18
+ });
@@ -0,0 +1,38 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { createI18n } from "vue-i18n";
4
+ import { setJskitI18n, useJskitText } from "@jskit-ai/kernel/client/i18n";
5
+ import { resolveCapacitorLaunchUrl } from "../src/client/runtime/oauthLaunchClient.js";
6
+ import { resolveCapacitorAbsoluteHttpUrl } from "../src/client/runtime/apiRequestClient.js";
7
+
8
+ function thrownBy(run) {
9
+ try {
10
+ run();
11
+ } catch (error) {
12
+ return error;
13
+ }
14
+ assert.fail("expected an error");
15
+ }
16
+
17
+ test("Capacitor URL errors keep their English and carry a messageCode for the user's language", () => {
18
+ const error = thrownBy(() => resolveCapacitorLaunchUrl("/api/oauth/google/start", ""));
19
+ assert.equal(error.message, "config.mobile.apiBaseUrl is required to launch OAuth from the Capacitor shell.");
20
+ assert.equal(error.messageCode, "mobile.oauth.apiBaseUrlRequired");
21
+
22
+ setJskitI18n(createI18n({
23
+ legacy: false,
24
+ locale: "xx",
25
+ messages: { xx: { jskit: { mobile: { oauth: { apiBaseUrlRequired: "[xx] apiBaseUrl manquant." } } } } }
26
+ }));
27
+ try {
28
+ assert.equal(useJskitText().errorMessage(error), "[xx] apiBaseUrl manquant.");
29
+ } finally {
30
+ setJskitI18n(null);
31
+ }
32
+ });
33
+
34
+ test("a caller's own message text is thrown as written", () => {
35
+ const error = thrownBy(() => resolveCapacitorAbsoluteHttpUrl("", "", { emptyUrlMessage: "Pick a URL first." }));
36
+ assert.equal(error.message, "Pick a URL first.");
37
+ assert.equal(error.messageCode, undefined);
38
+ });