@vnejs/plugins.bridges.plugins.platform.desktop.plugins.controllers.common.achievement 0.0.0-stage → 0.2.10
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/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/modules/bridge_plugin_desktop_plugin_achievement.d.ts +13 -0
- package/dist/modules/bridge_plugin_desktop_plugin_achievement.js +22 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.js +1 -0
- package/package.json +42 -4
- package/src/index.ts +7 -0
- package/src/modules/bridge_plugin_desktop_plugin_achievement.ts +35 -0
- package/src/tests/achievement.test.ts +31 -0
- package/src/tests/setup.ts +24 -0
- package/src/types.ts +15 -0
- package/tsconfig.json +9 -0
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { regPlugin } from "@vnejs/registry";
|
|
2
|
+
import { PLUGIN_NAME } from "@vnejs/contracts.bridges.plugins.platform.desktop.plugins.controllers.common.achievement";
|
|
3
|
+
import { BridgePluginDesktopPluginAchievement } from "./modules/bridge_plugin_desktop_plugin_achievement.js";
|
|
4
|
+
regPlugin(PLUGIN_NAME, {}, [BridgePluginDesktopPluginAchievement]);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "../types.js";
|
|
3
|
+
type AchievementIdPayload = {
|
|
4
|
+
id?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare class BridgePluginDesktopPluginAchievement extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
|
|
7
|
+
name: string;
|
|
8
|
+
subscribe: () => void;
|
|
9
|
+
onAchievementLocked: ({ id }?: AchievementIdPayload) => void;
|
|
10
|
+
onAchievementUnlocked: ({ id }?: AchievementIdPayload) => void;
|
|
11
|
+
fetch: (url: string, body: Record<string, unknown>) => Promise<Response>;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
const HEADERS = { "Content-Type": "application/json;charset=utf-8" };
|
|
3
|
+
export class BridgePluginDesktopPluginAchievement extends ModuleCore {
|
|
4
|
+
name = "bridge_plugin_desktop_plugin_achievement";
|
|
5
|
+
subscribe = () => {
|
|
6
|
+
if (this.PARAMS.PLATFORMS.CURRENT_PLATFORM !== this.CONST.PLATFORMS.DESKTOP)
|
|
7
|
+
return;
|
|
8
|
+
this.on(this.EVENTS.ACHIEVEMENT.LOCKED, this.onAchievementLocked);
|
|
9
|
+
this.on(this.EVENTS.ACHIEVEMENT.UNLOCKED, this.onAchievementUnlocked);
|
|
10
|
+
};
|
|
11
|
+
onAchievementLocked = ({ id = "" } = {}) => {
|
|
12
|
+
const data = this.PARAMS.ACHIEVEMENT.INFO[id];
|
|
13
|
+
if (data)
|
|
14
|
+
this.fetch("achievement/lock", { id, data });
|
|
15
|
+
};
|
|
16
|
+
onAchievementUnlocked = ({ id = "" } = {}) => {
|
|
17
|
+
const data = this.PARAMS.ACHIEVEMENT.INFO[id];
|
|
18
|
+
if (data)
|
|
19
|
+
this.fetch("achievement/unlock", { id, data });
|
|
20
|
+
};
|
|
21
|
+
fetch = (url, body) => fetch(`${this.CONST.SYSTEM.HOST}/${url}`, { method: "POST", headers: HEADERS, body: JSON.stringify(body) });
|
|
22
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
|
|
2
|
+
import type { Params as AchievementParams, PluginName as AchievementPluginName, SubscribeEvents as AchievementSubscribeEvents } from "@vnejs/contracts.controllers.common.achievement";
|
|
3
|
+
export type PluginEvents = ModuleCoreEvents & Record<AchievementPluginName, AchievementSubscribeEvents>;
|
|
4
|
+
export type PluginConstants = ModuleCoreConstants;
|
|
5
|
+
export type PluginSettings = ModuleCoreSettings;
|
|
6
|
+
export type PluginParams = ModuleCoreParams & Record<AchievementPluginName, AchievementParams>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.bridges.plugins.platform.desktop.plugins.controllers.common.achievement",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.10",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src",
|
|
18
|
+
"tsconfig.json"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "npx @vnejs/monorepo test",
|
|
22
|
+
"build": "npx @vnejs/monorepo package",
|
|
23
|
+
"publish:major:plugin": "npm run publish:major",
|
|
24
|
+
"publish:minor:plugin": "npm run publish:minor",
|
|
25
|
+
"publish:patch:plugin": "npm run publish:patch",
|
|
26
|
+
"publish:major": "npx @vnejs/monorepo publish major --access public",
|
|
27
|
+
"publish:minor": "npx @vnejs/monorepo publish minor --access public",
|
|
28
|
+
"publish:patch": "npx @vnejs/monorepo publish patch --access public"
|
|
29
|
+
},
|
|
30
|
+
"author": "",
|
|
31
|
+
"license": "ISC",
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@vnejs/module.core": "~0.2.0",
|
|
34
|
+
"@vnejs/contracts.controllers.common.achievement": "~0.2.0",
|
|
35
|
+
"@vnejs/registry": "~0.2.0",
|
|
36
|
+
"@vnejs/contracts.bridges.plugins.platform.desktop.plugins.controllers.common.achievement": "~0.2.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@vnejs/configs.ts-common": "~0.2.0",
|
|
40
|
+
"@vnejs/configs.vitest": "~0.2.0",
|
|
41
|
+
"@vnejs/test-utils": "~0.2.0",
|
|
42
|
+
"@vnejs/contracts.bridges.plugins.platform.desktop.plugins.controllers.common.achievement": "~0.2.0"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { regPlugin } from "@vnejs/registry";
|
|
2
|
+
|
|
3
|
+
import { PLUGIN_NAME } from "@vnejs/contracts.bridges.plugins.platform.desktop.plugins.controllers.common.achievement";
|
|
4
|
+
|
|
5
|
+
import { BridgePluginDesktopPluginAchievement } from "./modules/bridge_plugin_desktop_plugin_achievement.js";
|
|
6
|
+
|
|
7
|
+
regPlugin(PLUGIN_NAME, {}, [BridgePluginDesktopPluginAchievement]);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
|
|
3
|
+
import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "../types.js";
|
|
4
|
+
|
|
5
|
+
const HEADERS = { "Content-Type": "application/json;charset=utf-8" };
|
|
6
|
+
|
|
7
|
+
type AchievementIdPayload = {
|
|
8
|
+
id?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export class BridgePluginDesktopPluginAchievement extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
|
|
12
|
+
name = "bridge_plugin_desktop_plugin_achievement";
|
|
13
|
+
|
|
14
|
+
subscribe = () => {
|
|
15
|
+
if (this.PARAMS.PLATFORMS.CURRENT_PLATFORM !== this.CONST.PLATFORMS.DESKTOP) return;
|
|
16
|
+
|
|
17
|
+
this.on(this.EVENTS.ACHIEVEMENT.LOCKED, this.onAchievementLocked);
|
|
18
|
+
this.on(this.EVENTS.ACHIEVEMENT.UNLOCKED, this.onAchievementUnlocked);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
onAchievementLocked = ({ id = "" }: AchievementIdPayload = {}) => {
|
|
22
|
+
const data = this.PARAMS.ACHIEVEMENT.INFO[id as keyof typeof this.PARAMS.ACHIEVEMENT.INFO];
|
|
23
|
+
|
|
24
|
+
if (data) this.fetch("achievement/lock", { id, data });
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
onAchievementUnlocked = ({ id = "" }: AchievementIdPayload = {}) => {
|
|
28
|
+
const data = this.PARAMS.ACHIEVEMENT.INFO[id as keyof typeof this.PARAMS.ACHIEVEMENT.INFO];
|
|
29
|
+
|
|
30
|
+
if (data) this.fetch("achievement/unlock", { id, data });
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
fetch = (url: string, body: Record<string, unknown>) =>
|
|
34
|
+
fetch(`${this.CONST.SYSTEM.HOST}/${url}`, { method: "POST", headers: HEADERS, body: JSON.stringify(body) });
|
|
35
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { BridgePluginDesktopPluginAchievement } from "../modules/bridge_plugin_desktop_plugin_achievement.js";
|
|
6
|
+
|
|
7
|
+
import { ACHIEVEMENT_EVENTS, createCompatibilityTestModule, registerCompatibilityVne } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("BridgePluginDesktopPluginAchievement", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerCompatibilityVne();
|
|
12
|
+
vi.stubGlobal("fetch", vi.fn());
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("ACHIEVEMENT.UNLOCKED posts to electron host for known id", async () => {
|
|
16
|
+
const { observer } = createCompatibilityTestModule(BridgePluginDesktopPluginAchievement);
|
|
17
|
+
|
|
18
|
+
await observer.emit(ACHIEVEMENT_EVENTS.UNLOCKED, { id: "kekw" });
|
|
19
|
+
|
|
20
|
+
expect(fetch).toHaveBeenCalledOnce();
|
|
21
|
+
expect(String((fetch as ReturnType<typeof vi.fn>).mock.calls[0]?.[0])).toContain("achievement/unlock");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("ACHIEVEMENT.LOCKED ignores unknown id", async () => {
|
|
25
|
+
const { observer } = createCompatibilityTestModule(BridgePluginDesktopPluginAchievement);
|
|
26
|
+
|
|
27
|
+
await observer.emit(ACHIEVEMENT_EVENTS.LOCKED, { id: "missing" });
|
|
28
|
+
|
|
29
|
+
expect(fetch).not.toHaveBeenCalled();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { VNE } from "@vnejs/registry";
|
|
2
|
+
|
|
3
|
+
import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
PARAMS as ACHIEVEMENT_PARAMS,
|
|
7
|
+
SUBSCRIBE_EVENTS as ACHIEVEMENT_EVENTS,
|
|
8
|
+
PLUGIN_NAME as ACHIEVEMENT,
|
|
9
|
+
} from "@vnejs/contracts.controllers.common.achievement";
|
|
10
|
+
import { CONSTANTS as PLATFORMS_CONST, PARAMS as PLATFORMS_PARAMS, PLUGIN_NAME as PLATFORMS } from "@vnejs/contracts.core.platforms";
|
|
11
|
+
|
|
12
|
+
export const registerCompatibilityVne = () => {
|
|
13
|
+
registerCoreVne();
|
|
14
|
+
registerVnePlugin(PLATFORMS, { constants: PLATFORMS_CONST, params: { ...PLATFORMS_PARAMS, CURRENT_PLATFORM: PLATFORMS_CONST.DESKTOP } });
|
|
15
|
+
registerVnePlugin(ACHIEVEMENT, { events: ACHIEVEMENT_EVENTS, params: ACHIEVEMENT_PARAMS });
|
|
16
|
+
(VNE.PARAMS as Record<string, { CURRENT_PLATFORM?: string }>).PLATFORMS!.CURRENT_PLATFORM = PLATFORMS_CONST.DESKTOP;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const createCompatibilityTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
|
|
20
|
+
ModuleClass: T,
|
|
21
|
+
options: Parameters<typeof baseCreateTestModule>[1] = {},
|
|
22
|
+
) => baseCreateTestModule(ModuleClass, options);
|
|
23
|
+
|
|
24
|
+
export { ACHIEVEMENT_EVENTS };
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
Params as AchievementParams,
|
|
5
|
+
PluginName as AchievementPluginName,
|
|
6
|
+
SubscribeEvents as AchievementSubscribeEvents,
|
|
7
|
+
} from "@vnejs/contracts.controllers.common.achievement";
|
|
8
|
+
|
|
9
|
+
export type PluginEvents = ModuleCoreEvents & Record<AchievementPluginName, AchievementSubscribeEvents>;
|
|
10
|
+
|
|
11
|
+
export type PluginConstants = ModuleCoreConstants;
|
|
12
|
+
|
|
13
|
+
export type PluginSettings = ModuleCoreSettings;
|
|
14
|
+
|
|
15
|
+
export type PluginParams = ModuleCoreParams & Record<AchievementPluginName, AchievementParams>;
|
package/tsconfig.json
ADDED
package/README.md
DELETED