@jskit-ai/console-core 0.1.211 → 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,27 @@
|
|
|
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 (3)
|
|
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.console.owner.invalidUser`
|
|
14
|
+
- `jskit.console.owner.authenticationRequired`
|
|
15
|
+
- `jskit.console.owner.forbidden`
|
|
16
|
+
|
|
17
|
+
</details>
|
|
18
|
+
|
|
19
|
+
### Codes (3)
|
|
20
|
+
|
|
21
|
+
Error, field-error and message codes this package sends, with their English. Undotted codes kept their existing values and render from `jskit.errors.<code>`.
|
|
22
|
+
|
|
23
|
+
| Code | English |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| `console.owner.invalidUser` | Invalid console user. |
|
|
26
|
+
| `console.owner.authenticationRequired` | Authentication required. |
|
|
27
|
+
| `console.owner.forbidden` | Forbidden. |
|
package/locales/en.json
ADDED
package/package.json
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/console-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test --test-concurrency=1"
|
|
7
7
|
},
|
|
8
8
|
"exports": {
|
|
9
9
|
"./server/ConsoleFeature": "./src/server/ConsoleFeature.js",
|
|
10
|
-
"./shared/resources/consoleSettingsResource": "./src/shared/resources/consoleSettingsResource.js"
|
|
10
|
+
"./shared/resources/consoleSettingsResource": "./src/shared/resources/consoleSettingsResource.js",
|
|
11
|
+
"./locales/en.json": "./locales/en.json"
|
|
11
12
|
},
|
|
12
13
|
"dependencies": {
|
|
13
|
-
"@jskit-ai/database-runtime": "0.1.
|
|
14
|
-
"@jskit-ai/resource-crud-core": "0.1.
|
|
15
|
-
"@jskit-ai/users-core": "0.
|
|
14
|
+
"@jskit-ai/database-runtime": "0.1.249",
|
|
15
|
+
"@jskit-ai/resource-crud-core": "0.1.191",
|
|
16
|
+
"@jskit-ai/users-core": "0.2.0",
|
|
16
17
|
"json-rest-schema": "^1.0.17"
|
|
17
18
|
},
|
|
18
19
|
"description": "Console runtime: console settings schema, bootstrap flags, actions, and HTTP routes.",
|
|
@@ -94,8 +95,8 @@
|
|
|
94
95
|
}
|
|
95
96
|
},
|
|
96
97
|
"peerDependencies": {
|
|
97
|
-
"@jskit-ai/auth-core": "0.
|
|
98
|
-
"@jskit-ai/http-runtime": "0.
|
|
99
|
-
"@jskit-ai/kernel": "0.
|
|
98
|
+
"@jskit-ai/auth-core": "0.2.0",
|
|
99
|
+
"@jskit-ai/http-runtime": "0.2.0",
|
|
100
|
+
"@jskit-ai/kernel": "0.2.0"
|
|
100
101
|
}
|
|
101
102
|
}
|
|
@@ -12,7 +12,7 @@ function createService({ consoleSettingsRepository } = {}) {
|
|
|
12
12
|
async function ensureInitialConsoleMember(userId, options = {}) {
|
|
13
13
|
const normalizedUserId = normalizeRecordId(userId, { fallback: null });
|
|
14
14
|
if (!normalizedUserId) {
|
|
15
|
-
throw new AppError(400, "Invalid console user.");
|
|
15
|
+
throw new AppError(400, "Invalid console user.", { code: "console.owner.invalidUser" });
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
return consoleSettingsRepository.ensureOwnerUserId(normalizedUserId, options);
|
|
@@ -32,12 +32,12 @@ function createService({ consoleSettingsRepository } = {}) {
|
|
|
32
32
|
async function requireConsoleOwner(context = {}, options = {}) {
|
|
33
33
|
const actorUserId = normalizeRecordId(context?.actor?.id, { fallback: null });
|
|
34
34
|
if (!actorUserId) {
|
|
35
|
-
throw new AppError(401, "Authentication required.");
|
|
35
|
+
throw new AppError(401, "Authentication required.", { code: "console.owner.authenticationRequired" });
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
const ownerUserId = await ensureInitialConsoleMember(actorUserId, options);
|
|
39
39
|
if (actorUserId !== ownerUserId) {
|
|
40
|
-
throw new AppError(403, "Forbidden.");
|
|
40
|
+
throw new AppError(403, "Forbidden.", { code: "console.owner.forbidden" });
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -67,3 +67,23 @@ test("consoleService.requireConsoleOwner requires authentication", async () => {
|
|
|
67
67
|
(error) => error?.status === 401
|
|
68
68
|
);
|
|
69
69
|
});
|
|
70
|
+
|
|
71
|
+
test("consoleService errors carry console codes rendering their English", async () => {
|
|
72
|
+
const { catalogMessage, formatMessage, messageKeyForCode } = await import("@jskit-ai/kernel/shared/i18n");
|
|
73
|
+
const english = (await import("../locales/en.json", { with: { type: "json" } })).default;
|
|
74
|
+
const { service } = createFixture("1");
|
|
75
|
+
const failures = [
|
|
76
|
+
[() => service.ensureInitialConsoleMember("not-an-id"), 400, "console.owner.invalidUser"],
|
|
77
|
+
[() => service.requireConsoleOwner({}), 401, "console.owner.authenticationRequired"],
|
|
78
|
+
[() => service.requireConsoleOwner({ actor: { id: "2" } }), 403, "console.owner.forbidden"]
|
|
79
|
+
];
|
|
80
|
+
for (const [run, status, code] of failures) {
|
|
81
|
+
await assert.rejects(run, (error) => {
|
|
82
|
+
assert.equal(error.status, status);
|
|
83
|
+
assert.equal(error.code, code);
|
|
84
|
+
assert.deepEqual(error.params, {});
|
|
85
|
+
assert.equal(formatMessage(catalogMessage(english, messageKeyForCode(code)), error.params), error.message);
|
|
86
|
+
return true;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
});
|
|
@@ -15,7 +15,9 @@ test("console-core exports are explicit and aligned with production/template usa
|
|
|
15
15
|
packageId: "@jskit-ai/console-core",
|
|
16
16
|
requiredExports: [
|
|
17
17
|
"./server/ConsoleFeature",
|
|
18
|
-
"./shared/resources/consoleSettingsResource"
|
|
18
|
+
"./shared/resources/consoleSettingsResource",
|
|
19
|
+
// The generated client bootstrap registers it, so clients render console's codes.
|
|
20
|
+
"./locales/en.json"
|
|
19
21
|
]
|
|
20
22
|
});
|
|
21
23
|
|
|
@@ -0,0 +1,16 @@
|
|
|
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("console-core English catalog matches its source", () => {
|
|
11
|
+
const { problems } = evaluateI18nCatalogContract({
|
|
12
|
+
repoRoot: REPO_ROOT,
|
|
13
|
+
packageDir: path.join(REPO_ROOT, "packages", "console-core")
|
|
14
|
+
});
|
|
15
|
+
assert.deepEqual(problems, []);
|
|
16
|
+
});
|