@jskit-ai/rewarded-core 0.1.184 → 0.2.1
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 +49 -0
- package/locales/en.json +28 -0
- package/package.json +11 -10
- package/src/server/service.js +12 -10
- package/test/i18nCatalog.test.js +16 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
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 (14)
|
|
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.errors.rewarded_unlock_required`
|
|
14
|
+
- `jskit.errors.rewarded_cooldown_active`
|
|
15
|
+
- `jskit.errors.rewarded_daily_limit_reached`
|
|
16
|
+
- `jskit.errors.rewarded_not_configured`
|
|
17
|
+
- `jskit.errors.rewarded_unlock_blocked`
|
|
18
|
+
- `jskit.errors.rewarded_gate_state_invalid`
|
|
19
|
+
- `jskit.rewarded.auth.required`
|
|
20
|
+
- `jskit.rewarded.request.workspaceSlugRequired`
|
|
21
|
+
- `jskit.rewarded.request.gateKeyRequired`
|
|
22
|
+
- `jskit.rewarded.request.sessionIdRequired`
|
|
23
|
+
- `jskit.rewarded.session.notFound`
|
|
24
|
+
- `jskit.rewarded.session.grantNotAuthorized`
|
|
25
|
+
- `jskit.rewarded.session.closed`
|
|
26
|
+
- `jskit.rewarded.session.ruleMissing`
|
|
27
|
+
|
|
28
|
+
</details>
|
|
29
|
+
|
|
30
|
+
### Codes (14)
|
|
31
|
+
|
|
32
|
+
Error, field-error and message codes this package sends, with their English. Undotted codes kept their existing values and render from `jskit.errors.<code>`.
|
|
33
|
+
|
|
34
|
+
| Code | English |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| `rewarded_unlock_required` | Rewarded unlock required. |
|
|
37
|
+
| `rewarded_cooldown_active` | Rewarded unlock is cooling down. |
|
|
38
|
+
| `rewarded_daily_limit_reached` | Rewarded unlock limit reached. |
|
|
39
|
+
| `rewarded_not_configured` | Rewarded gate is not configured. |
|
|
40
|
+
| `rewarded_unlock_blocked` | Rewarded unlock is required before this action can continue. |
|
|
41
|
+
| `rewarded_gate_state_invalid` | Rewarded gate returned an invalid state. |
|
|
42
|
+
| `rewarded.auth.required` | Authentication required. |
|
|
43
|
+
| `rewarded.request.workspaceSlugRequired` | workspaceSlug is required. |
|
|
44
|
+
| `rewarded.request.gateKeyRequired` | gateKey is required. |
|
|
45
|
+
| `rewarded.request.sessionIdRequired` | sessionId is required. |
|
|
46
|
+
| `rewarded.session.notFound` | Watch session not found. |
|
|
47
|
+
| `rewarded.session.grantNotAuthorized` | Reward grant is not authorized. |
|
|
48
|
+
| `rewarded.session.closed` | Watch session is already closed. |
|
|
49
|
+
| `rewarded.session.ruleMissing` | No rewarded rule is configured for this session. |
|
package/locales/en.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"jskit": {
|
|
3
|
+
"errors": {
|
|
4
|
+
"rewarded_unlock_required": "Rewarded unlock required.",
|
|
5
|
+
"rewarded_cooldown_active": "Rewarded unlock is cooling down.",
|
|
6
|
+
"rewarded_daily_limit_reached": "Rewarded unlock limit reached.",
|
|
7
|
+
"rewarded_not_configured": "Rewarded gate is not configured.",
|
|
8
|
+
"rewarded_unlock_blocked": "Rewarded unlock is required before this action can continue.",
|
|
9
|
+
"rewarded_gate_state_invalid": "Rewarded gate returned an invalid state."
|
|
10
|
+
},
|
|
11
|
+
"rewarded": {
|
|
12
|
+
"auth": {
|
|
13
|
+
"required": "Authentication required."
|
|
14
|
+
},
|
|
15
|
+
"request": {
|
|
16
|
+
"workspaceSlugRequired": "workspaceSlug is required.",
|
|
17
|
+
"gateKeyRequired": "gateKey is required.",
|
|
18
|
+
"sessionIdRequired": "sessionId is required."
|
|
19
|
+
},
|
|
20
|
+
"session": {
|
|
21
|
+
"notFound": "Watch session not found.",
|
|
22
|
+
"grantNotAuthorized": "Reward grant is not authorized.",
|
|
23
|
+
"closed": "Watch session is already closed.",
|
|
24
|
+
"ruleMissing": "No rewarded rule is configured for this session."
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/rewarded-core",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test --test-concurrency=1"
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
"./shared": "./src/shared/index.js",
|
|
10
10
|
"./server/actions": "./src/server/actions.js",
|
|
11
|
-
"./server/requireRewardedUnlock": "./src/server/support/requireRewardedUnlock.js"
|
|
11
|
+
"./server/requireRewardedUnlock": "./src/server/support/requireRewardedUnlock.js",
|
|
12
|
+
"./locales/en.json": "./locales/en.json"
|
|
12
13
|
},
|
|
13
14
|
"description": "Rewarded workflow runtime plus internal CRUD providers for rules, provider configs, watch sessions, and unlock receipts.",
|
|
14
15
|
"jskit": {
|
|
@@ -119,16 +120,16 @@
|
|
|
119
120
|
}
|
|
120
121
|
},
|
|
121
122
|
"dependencies": {
|
|
122
|
-
"@jskit-ai/crud-core": "0.1
|
|
123
|
-
"@jskit-ai/database-runtime": "0.1.
|
|
124
|
-
"@jskit-ai/json-rest-api-core": "0.1
|
|
125
|
-
"@jskit-ai/resource-crud-core": "0.1.
|
|
126
|
-
"@jskit-ai/workspaces-core": "0.1
|
|
123
|
+
"@jskit-ai/crud-core": "0.2.1",
|
|
124
|
+
"@jskit-ai/database-runtime": "0.1.250",
|
|
125
|
+
"@jskit-ai/json-rest-api-core": "0.2.1",
|
|
126
|
+
"@jskit-ai/resource-crud-core": "0.1.192",
|
|
127
|
+
"@jskit-ai/workspaces-core": "0.2.1",
|
|
127
128
|
"json-rest-schema": "^1.0.17"
|
|
128
129
|
},
|
|
129
130
|
"peerDependencies": {
|
|
130
|
-
"@jskit-ai/auth-core": "0.1
|
|
131
|
-
"@jskit-ai/http-runtime": "0.1
|
|
132
|
-
"@jskit-ai/kernel": "0.1
|
|
131
|
+
"@jskit-ai/auth-core": "0.2.1",
|
|
132
|
+
"@jskit-ai/http-runtime": "0.2.1",
|
|
133
|
+
"@jskit-ai/kernel": "0.2.1"
|
|
133
134
|
}
|
|
134
135
|
}
|
package/src/server/service.js
CHANGED
|
@@ -58,7 +58,7 @@ function requireActor(context, input) {
|
|
|
58
58
|
const actor = resolveActionUser(context, input);
|
|
59
59
|
const actorId = actor?.id == null ? "" : String(actor.id).trim();
|
|
60
60
|
if (!actorId) {
|
|
61
|
-
throw new AppError(401, "Authentication required.");
|
|
61
|
+
throw new AppError(401, "Authentication required.", { code: "rewarded.auth.required" });
|
|
62
62
|
}
|
|
63
63
|
return actor;
|
|
64
64
|
}
|
|
@@ -66,7 +66,7 @@ function requireActor(context, input) {
|
|
|
66
66
|
function requireWorkspaceSlug(input = {}) {
|
|
67
67
|
const workspaceSlug = normalizeText(input?.workspaceSlug).toLowerCase();
|
|
68
68
|
if (!workspaceSlug) {
|
|
69
|
-
throw new AppError(400, "workspaceSlug is required.");
|
|
69
|
+
throw new AppError(400, "workspaceSlug is required.", { code: "rewarded.request.workspaceSlugRequired" });
|
|
70
70
|
}
|
|
71
71
|
return workspaceSlug;
|
|
72
72
|
}
|
|
@@ -74,7 +74,7 @@ function requireWorkspaceSlug(input = {}) {
|
|
|
74
74
|
function requireGateKey(input = {}) {
|
|
75
75
|
const gateKey = normalizeGateKey(input?.gateKey);
|
|
76
76
|
if (!gateKey) {
|
|
77
|
-
throw new AppError(400, "gateKey is required.");
|
|
77
|
+
throw new AppError(400, "gateKey is required.", { code: "rewarded.request.gateKeyRequired" });
|
|
78
78
|
}
|
|
79
79
|
return gateKey;
|
|
80
80
|
}
|
|
@@ -416,7 +416,7 @@ function createService({
|
|
|
416
416
|
const workspaceSlug = requireWorkspaceSlug(input);
|
|
417
417
|
const sessionId = input?.sessionId == null ? "" : String(input.sessionId).trim();
|
|
418
418
|
if (!sessionId) {
|
|
419
|
-
throw new AppError(400, "sessionId is required.");
|
|
419
|
+
throw new AppError(400, "sessionId is required.", { code: "rewarded.request.sessionIdRequired" });
|
|
420
420
|
}
|
|
421
421
|
|
|
422
422
|
return rewardedWatchSessionsRepository.withTransaction(async (trx) => {
|
|
@@ -425,7 +425,7 @@ function createService({
|
|
|
425
425
|
trx
|
|
426
426
|
}));
|
|
427
427
|
if (!sessionRecord) {
|
|
428
|
-
throw new AppError(404, "Watch session not found.");
|
|
428
|
+
throw new AppError(404, "Watch session not found.", { code: "rewarded.session.notFound" });
|
|
429
429
|
}
|
|
430
430
|
|
|
431
431
|
const authorized = await authorizeGrant({
|
|
@@ -434,11 +434,11 @@ function createService({
|
|
|
434
434
|
trx
|
|
435
435
|
});
|
|
436
436
|
if (authorized !== true) {
|
|
437
|
-
throw new AppError(403, "Reward grant is not authorized.");
|
|
437
|
+
throw new AppError(403, "Reward grant is not authorized.", { code: "rewarded.session.grantNotAuthorized" });
|
|
438
438
|
}
|
|
439
439
|
|
|
440
440
|
if (normalizeText(sessionRecord.status).toLowerCase() === "closed") {
|
|
441
|
-
throw new AppError(409, "Watch session is already closed.");
|
|
441
|
+
throw new AppError(409, "Watch session is already closed.", { code: "rewarded.session.closed" });
|
|
442
442
|
}
|
|
443
443
|
if (sessionRecord.rewardedAt || normalizeText(sessionRecord.status).toLowerCase() === "rewarded") {
|
|
444
444
|
const receiptRecord = await queryFirst(rewardedUnlockReceiptsRepository, {
|
|
@@ -465,7 +465,9 @@ function createService({
|
|
|
465
465
|
trx
|
|
466
466
|
});
|
|
467
467
|
if (!ruleRecord) {
|
|
468
|
-
throw new AppError(409, "No rewarded rule is configured for this session."
|
|
468
|
+
throw new AppError(409, "No rewarded rule is configured for this session.", {
|
|
469
|
+
code: "rewarded.session.ruleMissing"
|
|
470
|
+
});
|
|
469
471
|
}
|
|
470
472
|
|
|
471
473
|
const now = new Date();
|
|
@@ -514,7 +516,7 @@ function createService({
|
|
|
514
516
|
const workspaceSlug = requireWorkspaceSlug(input);
|
|
515
517
|
const sessionId = input?.sessionId == null ? "" : String(input.sessionId).trim();
|
|
516
518
|
if (!sessionId) {
|
|
517
|
-
throw new AppError(400, "sessionId is required.");
|
|
519
|
+
throw new AppError(400, "sessionId is required.", { code: "rewarded.request.sessionIdRequired" });
|
|
518
520
|
}
|
|
519
521
|
|
|
520
522
|
const sessionRecord = normalizeRecord(await rewardedWatchSessionsRepository.getDocumentById(sessionId, {}, {
|
|
@@ -522,7 +524,7 @@ function createService({
|
|
|
522
524
|
trx: options?.trx || null
|
|
523
525
|
}));
|
|
524
526
|
if (!sessionRecord) {
|
|
525
|
-
throw new AppError(404, "Watch session not found.");
|
|
527
|
+
throw new AppError(404, "Watch session not found.", { code: "rewarded.session.notFound" });
|
|
526
528
|
}
|
|
527
529
|
|
|
528
530
|
if (sessionRecord.rewardedAt || normalizeText(sessionRecord.status).toLowerCase() === "rewarded") {
|
|
@@ -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("rewarded-core English catalog matches its source", () => {
|
|
11
|
+
const { problems } = evaluateI18nCatalogContract({
|
|
12
|
+
repoRoot: REPO_ROOT,
|
|
13
|
+
packageDir: path.join(REPO_ROOT, "packages", "rewarded-core")
|
|
14
|
+
});
|
|
15
|
+
assert.deepEqual(problems, []);
|
|
16
|
+
});
|