@jskit-ai/rewarded-web 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,34 @@
|
|
|
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 (11)
|
|
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.rewarded.gate.eyebrow`
|
|
14
|
+
- `jskit.rewarded.gate.defaultTitle`
|
|
15
|
+
- `jskit.rewarded.gate.defaultDescription`
|
|
16
|
+
- `jskit.rewarded.gate.loading`
|
|
17
|
+
- `jskit.rewarded.gate.startFailed`
|
|
18
|
+
- `jskit.rewarded.gate.watch`
|
|
19
|
+
- `jskit.rewarded.gate.notNow`
|
|
20
|
+
- `jskit.rewarded.gate.close`
|
|
21
|
+
- `jskit.rewarded.gate.adUnavailable`
|
|
22
|
+
- `jskit.rewarded.gate.invalidState`
|
|
23
|
+
- `jskit.rewarded.gate.alreadyActive`
|
|
24
|
+
|
|
25
|
+
</details>
|
|
26
|
+
|
|
27
|
+
### Codes (2)
|
|
28
|
+
|
|
29
|
+
Error, field-error and message codes this package sends, with their English. Undotted codes kept their existing values and render from `jskit.errors.<code>`.
|
|
30
|
+
|
|
31
|
+
| Code | English |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| `rewarded.gate.invalidState` | Rewarded gate returned an invalid state. |
|
|
34
|
+
| `rewarded.gate.alreadyActive` | A Rewarded gate is already active. |
|
package/locales/en.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"jskit": {
|
|
3
|
+
"rewarded": {
|
|
4
|
+
"gate": {
|
|
5
|
+
"eyebrow": "Rewarded unlock",
|
|
6
|
+
"defaultTitle": "Watch an ad to continue",
|
|
7
|
+
"defaultDescription": "Watch a rewarded ad to unlock this action.",
|
|
8
|
+
"loading": "Loading Rewarded ad…",
|
|
9
|
+
"startFailed": "Unable to start the rewarded ad.",
|
|
10
|
+
"watch": "Watch ad",
|
|
11
|
+
"notNow": "Not now",
|
|
12
|
+
"close": "Close",
|
|
13
|
+
"adUnavailable": "No rewarded ad was available right now. Please try again later.",
|
|
14
|
+
"invalidState": "Rewarded gate returned an invalid state.",
|
|
15
|
+
"alreadyActive": "A Rewarded gate is already active."
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/rewarded-web",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test --test-concurrency=1"
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
".": "./src/index.js",
|
|
10
10
|
"./client": "./src/client/index.js",
|
|
11
11
|
"./server": "./src/server/index.js",
|
|
12
|
-
"./shared": "./src/shared/index.js"
|
|
12
|
+
"./shared": "./src/shared/index.js",
|
|
13
|
+
"./locales/en.json": "./locales/en.json"
|
|
13
14
|
},
|
|
14
15
|
"description": "Rewarded gate client workflow with explicitly composed application delivery.",
|
|
15
16
|
"jskit": {
|
|
@@ -54,12 +55,12 @@
|
|
|
54
55
|
}
|
|
55
56
|
},
|
|
56
57
|
"dependencies": {
|
|
57
|
-
"@jskit-ai/rewarded-core": "0.
|
|
58
|
+
"@jskit-ai/rewarded-core": "0.2.0"
|
|
58
59
|
},
|
|
59
60
|
"peerDependencies": {
|
|
60
|
-
"@jskit-ai/http-runtime": "0.
|
|
61
|
-
"@jskit-ai/kernel": "0.
|
|
62
|
-
"@jskit-ai/shell-web": "0.
|
|
61
|
+
"@jskit-ai/http-runtime": "0.2.0",
|
|
62
|
+
"@jskit-ai/kernel": "0.2.0",
|
|
63
|
+
"@jskit-ai/shell-web": "0.2.0",
|
|
63
64
|
"vue": "^3.5.13"
|
|
64
65
|
}
|
|
65
66
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed } from "vue";
|
|
3
3
|
import { useRewardedRuntime } from "../composables/useRewardedRuntime.js";
|
|
4
|
+
import { useJskitText } from "../i18n.js";
|
|
4
5
|
|
|
5
6
|
const props = defineProps({
|
|
6
7
|
runtime: {
|
|
@@ -10,16 +11,17 @@ const props = defineProps({
|
|
|
10
11
|
}
|
|
11
12
|
});
|
|
12
13
|
|
|
14
|
+
const { t } = useJskitText();
|
|
13
15
|
const runtime = computed(() => props.runtime || useRewardedRuntime());
|
|
14
16
|
const state = computed(() => runtime.value?.state || null);
|
|
15
17
|
const isVisible = computed(() => {
|
|
16
18
|
const currentState = state.value;
|
|
17
19
|
return currentState?.open === true && currentState?.phase !== "showing-ad";
|
|
18
20
|
});
|
|
19
|
-
const titleText = computed(() => state.value?.gateState?.rule?.title || "
|
|
21
|
+
const titleText = computed(() => state.value?.gateState?.rule?.title || t("jskit.rewarded.gate.defaultTitle"));
|
|
20
22
|
const descriptionText = computed(() =>
|
|
21
23
|
state.value?.gateState?.rule?.description ||
|
|
22
|
-
"
|
|
24
|
+
t("jskit.rewarded.gate.defaultDescription")
|
|
23
25
|
);
|
|
24
26
|
|
|
25
27
|
function handleWatchClick() {
|
|
@@ -40,7 +42,7 @@ function handleDismissError() {
|
|
|
40
42
|
<div v-if="isVisible" class="rewarded-gate">
|
|
41
43
|
<div class="rewarded-gate__scrim" />
|
|
42
44
|
<div class="rewarded-gate__panel">
|
|
43
|
-
<div class="rewarded-gate__eyebrow">
|
|
45
|
+
<div class="rewarded-gate__eyebrow">{{ t("jskit.rewarded.gate.eyebrow") }}</div>
|
|
44
46
|
<h2 class="rewarded-gate__title">{{ titleText }}</h2>
|
|
45
47
|
<p class="rewarded-gate__description">{{ descriptionText }}</p>
|
|
46
48
|
|
|
@@ -48,14 +50,14 @@ function handleDismissError() {
|
|
|
48
50
|
v-if="state?.phase === 'loading'"
|
|
49
51
|
class="rewarded-gate__status"
|
|
50
52
|
>
|
|
51
|
-
|
|
53
|
+
{{ t("jskit.rewarded.gate.loading") }}
|
|
52
54
|
</p>
|
|
53
55
|
|
|
54
56
|
<p
|
|
55
57
|
v-else-if="state?.phase === 'error'"
|
|
56
58
|
class="rewarded-gate__status rewarded-gate__status--error"
|
|
57
59
|
>
|
|
58
|
-
{{ state?.errorMessage || "
|
|
60
|
+
{{ state?.errorMessage || t("jskit.rewarded.gate.startFailed") }}
|
|
59
61
|
</p>
|
|
60
62
|
|
|
61
63
|
<div class="rewarded-gate__actions">
|
|
@@ -65,7 +67,7 @@ function handleDismissError() {
|
|
|
65
67
|
class="rewarded-gate__button rewarded-gate__button--primary"
|
|
66
68
|
@click="handleWatchClick"
|
|
67
69
|
>
|
|
68
|
-
|
|
70
|
+
{{ t("jskit.rewarded.gate.watch") }}
|
|
69
71
|
</button>
|
|
70
72
|
|
|
71
73
|
<button
|
|
@@ -74,7 +76,7 @@ function handleDismissError() {
|
|
|
74
76
|
class="rewarded-gate__button"
|
|
75
77
|
@click="handleCancelClick"
|
|
76
78
|
>
|
|
77
|
-
|
|
79
|
+
{{ t("jskit.rewarded.gate.notNow") }}
|
|
78
80
|
</button>
|
|
79
81
|
|
|
80
82
|
<button
|
|
@@ -83,7 +85,7 @@ function handleDismissError() {
|
|
|
83
85
|
class="rewarded-gate__button rewarded-gate__button--primary"
|
|
84
86
|
@click="handleDismissError"
|
|
85
87
|
>
|
|
86
|
-
|
|
88
|
+
{{ t("jskit.rewarded.gate.close") }}
|
|
87
89
|
</button>
|
|
88
90
|
</div>
|
|
89
91
|
</div>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { reactive } from "vue";
|
|
2
2
|
import { createHttpClient } from "@jskit-ai/http-runtime/client";
|
|
3
|
+
import { useJskitText } from "../i18n.js";
|
|
3
4
|
|
|
4
5
|
const REWARDED_RUNTIME_INJECTION_KEY = Symbol("rewarded.web.runtime");
|
|
5
6
|
const REWARDED_CONFIGURATION_REASONS = new Set([
|
|
@@ -30,6 +31,11 @@ function createInitialState() {
|
|
|
30
31
|
};
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
// The English stays the message; messageCode lets the app show it in its language.
|
|
35
|
+
function rewardedClientError(message, { messageCode }) {
|
|
36
|
+
return Object.assign(new Error(message), { messageCode, messageParams: {} });
|
|
37
|
+
}
|
|
38
|
+
|
|
33
39
|
function applyState(target, source) {
|
|
34
40
|
for (const key of Object.keys(target)) {
|
|
35
41
|
if (!Object.hasOwn(source, key)) {
|
|
@@ -74,6 +80,7 @@ function createRewardedRuntime({ launchReward } = {}) {
|
|
|
74
80
|
if (typeof launchReward !== "function") {
|
|
75
81
|
throw new TypeError("Rewarded runtime requires an explicit launchReward delivery function.");
|
|
76
82
|
}
|
|
83
|
+
const { t, errorMessage } = useJskitText();
|
|
77
84
|
const state = reactive(createInitialState());
|
|
78
85
|
let pendingResolve = null;
|
|
79
86
|
let activeGrantPromise = null;
|
|
@@ -156,7 +163,7 @@ async function requestCurrent(input = {}) {
|
|
|
156
163
|
workspaceSlug
|
|
157
164
|
});
|
|
158
165
|
if (!isWellFormedGateState(gateState)) {
|
|
159
|
-
throw
|
|
166
|
+
throw rewardedClientError("Rewarded gate returned an invalid state.", { messageCode: "rewarded.gate.invalidState" });
|
|
160
167
|
}
|
|
161
168
|
const alreadyUnlocked = gateState?.blocked === false && gateState?.unlock;
|
|
162
169
|
if (!gateState?.enabled || !gateState?.blocked) {
|
|
@@ -167,7 +174,7 @@ async function requestCurrent(input = {}) {
|
|
|
167
174
|
}
|
|
168
175
|
|
|
169
176
|
if (pendingResolve) {
|
|
170
|
-
throw
|
|
177
|
+
throw rewardedClientError("A Rewarded gate is already active.", { messageCode: "rewarded.gate.alreadyActive" });
|
|
171
178
|
}
|
|
172
179
|
|
|
173
180
|
applyState(state, {
|
|
@@ -271,7 +278,7 @@ async function requestCurrent(input = {}) {
|
|
|
271
278
|
applyState(state, {
|
|
272
279
|
...state,
|
|
273
280
|
phase: "error",
|
|
274
|
-
errorMessage: "
|
|
281
|
+
errorMessage: t("jskit.rewarded.gate.adUnavailable")
|
|
275
282
|
});
|
|
276
283
|
}
|
|
277
284
|
});
|
|
@@ -279,7 +286,7 @@ async function requestCurrent(input = {}) {
|
|
|
279
286
|
applyState(state, {
|
|
280
287
|
...state,
|
|
281
288
|
phase: "error",
|
|
282
|
-
errorMessage: error instanceof Error ? error
|
|
289
|
+
errorMessage: error instanceof Error ? errorMessage(error) : String(error)
|
|
283
290
|
});
|
|
284
291
|
}
|
|
285
292
|
}
|
|
@@ -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-web English catalog matches its source", () => {
|
|
11
|
+
const { problems } = evaluateI18nCatalogContract({
|
|
12
|
+
repoRoot: REPO_ROOT,
|
|
13
|
+
packageDir: path.join(REPO_ROOT, "packages", "rewarded-web")
|
|
14
|
+
});
|
|
15
|
+
assert.deepEqual(problems, []);
|
|
16
|
+
});
|