@takaro/modules 0.4.10 → 0.4.11
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/package.json
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takaro/modules",
|
|
3
|
-
"version": "0.4.10",
|
|
4
3
|
"description": "Built-in modules for Takaro",
|
|
4
|
+
"version": "0.4.11",
|
|
5
|
+
"author": "",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"class-transformer": "0.5.1",
|
|
8
|
+
"class-validator": "0.14.2"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [],
|
|
11
|
+
"license": "ISC",
|
|
5
12
|
"main": "dist/main.js",
|
|
6
|
-
"
|
|
7
|
-
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"@takaro/apiclient": "*",
|
|
15
|
+
"@takaro/helpers": "*",
|
|
16
|
+
"@takaro/util": "*"
|
|
17
|
+
},
|
|
8
18
|
"scripts": {
|
|
9
|
-
"start:dev": "tsc --watch --preserveWatchOutput -p ./tsconfig.build.json",
|
|
10
19
|
"build": "tsc -p ./tsconfig.build.json",
|
|
20
|
+
"build:builtin-json": "node --import=ts-node-maintained/register/esm ./scripts/buildBuiltinJson.ts",
|
|
11
21
|
"postbuild": "npm run build:builtin-json",
|
|
12
|
-
"
|
|
22
|
+
"start:dev": ":"
|
|
13
23
|
},
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"license": "ISC"
|
|
24
|
+
"type": "module",
|
|
25
|
+
"types": "dist/main.d.ts"
|
|
17
26
|
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { IntegrationTest, expect, IModuleTestsSetupData, modulesTestSetup, EventsAwaiter } from '@takaro/test';
|
|
2
|
+
import { GameEvents } from '../dto/index.js';
|
|
3
|
+
import { describe } from 'node:test';
|
|
4
|
+
|
|
5
|
+
const group = 'DefaultSystemConfig Aliases';
|
|
6
|
+
|
|
7
|
+
const tests = [
|
|
8
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
9
|
+
group,
|
|
10
|
+
snapshot: false,
|
|
11
|
+
name: 'Custom module with defaultSystemConfig aliases should work after installation',
|
|
12
|
+
setup: modulesTestSetup,
|
|
13
|
+
test: async function () {
|
|
14
|
+
// Create a module WITHOUT defaultSystemConfig first
|
|
15
|
+
const mod = (
|
|
16
|
+
await this.client.module.moduleControllerCreate({
|
|
17
|
+
name: 'Test Module With Default Aliases',
|
|
18
|
+
latestVersion: {
|
|
19
|
+
description: 'Testing defaultSystemConfig aliases',
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
).data.data;
|
|
23
|
+
|
|
24
|
+
// Create a command in the module FIRST
|
|
25
|
+
await this.client.command.commandControllerCreate({
|
|
26
|
+
name: 'pingcommand',
|
|
27
|
+
description: 'Test ping command',
|
|
28
|
+
trigger: 'ping',
|
|
29
|
+
versionId: mod.latestVersion.id,
|
|
30
|
+
function: `import { data, takaro } from '@takaro/helpers';
|
|
31
|
+
async function main() {
|
|
32
|
+
await takaro.gameserver.gameServerControllerSendMessage(data.gameServerId, {
|
|
33
|
+
message: 'command executed via alias',
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
await main();`,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// THEN update module with defaultSystemConfig (now command exists, schema is valid)
|
|
40
|
+
await this.client.module.moduleControllerUpdate(mod.id, {
|
|
41
|
+
latestVersion: {
|
|
42
|
+
defaultSystemConfig: JSON.stringify({
|
|
43
|
+
commands: {
|
|
44
|
+
pingcommand: {
|
|
45
|
+
aliases: ['pong', 'pp'],
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Install the module WITHOUT providing explicit systemConfig
|
|
53
|
+
// This should use the defaultSystemConfig with aliases
|
|
54
|
+
await this.client.module.moduleInstallationsControllerInstallModule({
|
|
55
|
+
gameServerId: this.setupData.gameserver.id,
|
|
56
|
+
versionId: mod.latestVersion.id,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Try to trigger the command using the alias from defaultSystemConfig
|
|
60
|
+
const events = (await new EventsAwaiter().connect(this.client)).waitForEvents(GameEvents.CHAT_MESSAGE, 1);
|
|
61
|
+
|
|
62
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
63
|
+
msg: '/pong', // Using the alias from defaultSystemConfig
|
|
64
|
+
playerId: this.setupData.players[0].id,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Verify the command executed
|
|
68
|
+
const receivedEvents = await events;
|
|
69
|
+
expect(receivedEvents.length).to.be.eq(1);
|
|
70
|
+
expect(receivedEvents[0].data.meta.msg).to.be.eq('command executed via alias');
|
|
71
|
+
},
|
|
72
|
+
}),
|
|
73
|
+
|
|
74
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
75
|
+
group,
|
|
76
|
+
snapshot: false,
|
|
77
|
+
name: 'Custom module aliases work when explicitly provided during installation',
|
|
78
|
+
setup: modulesTestSetup,
|
|
79
|
+
test: async function () {
|
|
80
|
+
// Create a module WITHOUT defaultSystemConfig first
|
|
81
|
+
const mod = (
|
|
82
|
+
await this.client.module.moduleControllerCreate({
|
|
83
|
+
name: 'Test Module Explicit Aliases',
|
|
84
|
+
latestVersion: {
|
|
85
|
+
description: 'Testing explicit aliases',
|
|
86
|
+
},
|
|
87
|
+
})
|
|
88
|
+
).data.data;
|
|
89
|
+
|
|
90
|
+
// Create command FIRST
|
|
91
|
+
await this.client.command.commandControllerCreate({
|
|
92
|
+
name: 'echocommand',
|
|
93
|
+
description: 'Test echo command',
|
|
94
|
+
trigger: 'echo',
|
|
95
|
+
versionId: mod.latestVersion.id,
|
|
96
|
+
function: `import { data, takaro } from '@takaro/helpers';
|
|
97
|
+
async function main() {
|
|
98
|
+
await takaro.gameserver.gameServerControllerSendMessage(data.gameServerId, {
|
|
99
|
+
message: 'command executed',
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
await main();`,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// THEN update module with defaultSystemConfig
|
|
106
|
+
await this.client.module.moduleControllerUpdate(mod.id, {
|
|
107
|
+
latestVersion: {
|
|
108
|
+
defaultSystemConfig: JSON.stringify({
|
|
109
|
+
commands: {
|
|
110
|
+
echocommand: {
|
|
111
|
+
aliases: ['defaultalias'],
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
}),
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Install the module WITH explicit systemConfig (overriding defaults)
|
|
119
|
+
await this.client.module.moduleInstallationsControllerInstallModule({
|
|
120
|
+
gameServerId: this.setupData.gameserver.id,
|
|
121
|
+
versionId: mod.latestVersion.id,
|
|
122
|
+
systemConfig: JSON.stringify({
|
|
123
|
+
commands: {
|
|
124
|
+
echocommand: {
|
|
125
|
+
aliases: ['explicitalias', 'ea'],
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
}),
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Verify explicit alias works
|
|
132
|
+
const events = (await new EventsAwaiter().connect(this.client)).waitForEvents(GameEvents.CHAT_MESSAGE, 1);
|
|
133
|
+
|
|
134
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
135
|
+
msg: '/explicitalias',
|
|
136
|
+
playerId: this.setupData.players[0].id,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const receivedEvents = await events;
|
|
140
|
+
expect(receivedEvents.length).to.be.eq(1);
|
|
141
|
+
expect(receivedEvents[0].data.meta.msg).to.be.eq('command executed');
|
|
142
|
+
},
|
|
143
|
+
}),
|
|
144
|
+
|
|
145
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
146
|
+
group,
|
|
147
|
+
snapshot: false,
|
|
148
|
+
name: 'Multiple aliases from defaultSystemConfig should all work',
|
|
149
|
+
setup: modulesTestSetup,
|
|
150
|
+
test: async function () {
|
|
151
|
+
// Create module WITHOUT defaultSystemConfig first
|
|
152
|
+
const mod = (
|
|
153
|
+
await this.client.module.moduleControllerCreate({
|
|
154
|
+
name: 'Test Module Multiple Aliases',
|
|
155
|
+
latestVersion: {
|
|
156
|
+
description: 'Testing multiple aliases',
|
|
157
|
+
},
|
|
158
|
+
})
|
|
159
|
+
).data.data;
|
|
160
|
+
|
|
161
|
+
// Create command FIRST
|
|
162
|
+
await this.client.command.commandControllerCreate({
|
|
163
|
+
name: 'testcmd',
|
|
164
|
+
description: 'Test command',
|
|
165
|
+
trigger: 'test',
|
|
166
|
+
versionId: mod.latestVersion.id,
|
|
167
|
+
function: `import { data, takaro } from '@takaro/helpers';
|
|
168
|
+
async function main() {
|
|
169
|
+
await takaro.gameserver.gameServerControllerSendMessage(data.gameServerId, {
|
|
170
|
+
message: 'success',
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
await main();`,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// THEN update module with defaultSystemConfig
|
|
177
|
+
await this.client.module.moduleControllerUpdate(mod.id, {
|
|
178
|
+
latestVersion: {
|
|
179
|
+
defaultSystemConfig: JSON.stringify({
|
|
180
|
+
commands: {
|
|
181
|
+
testcmd: {
|
|
182
|
+
aliases: ['alias1', 'alias2', 'alias3'],
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
}),
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
await this.client.module.moduleInstallationsControllerInstallModule({
|
|
190
|
+
gameServerId: this.setupData.gameserver.id,
|
|
191
|
+
versionId: mod.latestVersion.id,
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// Test each alias
|
|
195
|
+
for (const alias of ['alias1', 'alias2', 'alias3']) {
|
|
196
|
+
const events = (await new EventsAwaiter().connect(this.client)).waitForEvents(GameEvents.CHAT_MESSAGE, 1);
|
|
197
|
+
|
|
198
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
199
|
+
msg: `/${alias}`,
|
|
200
|
+
playerId: this.setupData.players[0].id,
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const receivedEvents = await events;
|
|
204
|
+
expect(receivedEvents.length).to.be.eq(1);
|
|
205
|
+
expect(receivedEvents[0].data.meta.msg).to.be.eq('success');
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
}),
|
|
209
|
+
];
|
|
210
|
+
|
|
211
|
+
describe(group, () => {
|
|
212
|
+
tests.forEach((test) => {
|
|
213
|
+
test.run();
|
|
214
|
+
});
|
|
215
|
+
});
|
package/tsconfig.build.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "./tsconfig.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
+
"composite": true,
|
|
4
5
|
"rootDir": "./src",
|
|
5
6
|
"outDir": "dist",
|
|
6
7
|
"allowJs": true
|
|
7
8
|
},
|
|
8
9
|
"include": ["src/**/*"],
|
|
9
|
-
"exclude": ["src/**/*.test.ts"]
|
|
10
|
+
"exclude": ["src/**/*.test.ts"],
|
|
11
|
+
"references": [
|
|
12
|
+
{ "path": "../lib-util/tsconfig.build.json" }
|
|
13
|
+
]
|
|
10
14
|
}
|