@takaro/helpers 0.0.0-dev.39c315f → 0.0.0-dev.3abbd4a
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/.source-hash +1 -1
- package/dist/commandRejection.d.ts +10 -0
- package/dist/commandRejection.d.ts.map +1 -0
- package/dist/commandRejection.js +41 -0
- package/dist/commandRejection.js.map +1 -0
- package/dist/getTakaro.d.ts.map +1 -1
- package/dist/getTakaro.js +4 -2
- package/dist/getTakaro.js.map +1 -1
- package/package.json +4 -4
package/dist/.source-hash
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
79625e19e53624d3d0c58cf66c63d639f05c0e9b404dfdb4847d29150c1ef065
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Client } from '@takaro/apiclient';
|
|
2
|
+
export declare class GameServerCommandRejectedError extends Error {
|
|
3
|
+
readonly command: string;
|
|
4
|
+
readonly rawResult: string;
|
|
5
|
+
readonly errorMessage?: string | undefined;
|
|
6
|
+
constructor(command: string, rawResult: string, errorMessage?: string | undefined);
|
|
7
|
+
}
|
|
8
|
+
/** Wraps only the module-facing client, so app-api's own clients keep seeing `success: false` as a normal answer. */
|
|
9
|
+
export declare function rejectUnsuccessfulCommands(client: Client): Client;
|
|
10
|
+
//# sourceMappingURL=commandRejection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandRejection.d.ts","sourceRoot":"","sources":["../src/commandRejection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,8BAA+B,SAAQ,KAAK;IAErD,QAAQ,CAAC,OAAO,EAAE,MAAM;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM;IAC1B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM;IAHhC,YACW,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,MAAM,YAAA,EAK/B;CACF;AAgBD,qHAAqH;AACrH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAiBjE"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export class GameServerCommandRejectedError extends Error {
|
|
2
|
+
constructor(command, rawResult, errorMessage) {
|
|
3
|
+
const answer = [errorMessage, rawResult].find((text) => text) ?? 'no reason given';
|
|
4
|
+
super(`The game server rejected the command "${command}": ${answer}`);
|
|
5
|
+
this.command = command;
|
|
6
|
+
this.rawResult = rawResult;
|
|
7
|
+
this.errorMessage = errorMessage;
|
|
8
|
+
this.name = 'GameServerCommandRejectedError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function failOnRejection(execute) {
|
|
12
|
+
return async (...args) => {
|
|
13
|
+
const response = await execute(...args);
|
|
14
|
+
const output = response.data.data;
|
|
15
|
+
// The Rust connector never reports `success` despite the generated type, so only an explicit false is a rejection.
|
|
16
|
+
if (output.success === false) {
|
|
17
|
+
throw new GameServerCommandRejectedError(args[1]?.command ?? '', output.rawResult, output.errorMessage);
|
|
18
|
+
}
|
|
19
|
+
return response;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** Wraps only the module-facing client, so app-api's own clients keep seeing `success: false` as a normal answer. */
|
|
23
|
+
export function rejectUnsuccessfulCommands(client) {
|
|
24
|
+
return new Proxy(client, {
|
|
25
|
+
get(target, property) {
|
|
26
|
+
if (property !== 'gameserver') {
|
|
27
|
+
return Reflect.get(target, property, target);
|
|
28
|
+
}
|
|
29
|
+
const api = target.gameserver;
|
|
30
|
+
return new Proxy(api, {
|
|
31
|
+
get(apiTarget, apiProperty) {
|
|
32
|
+
if (apiProperty === 'gameServerControllerExecuteCommand') {
|
|
33
|
+
return failOnRejection(apiTarget.gameServerControllerExecuteCommand.bind(apiTarget));
|
|
34
|
+
}
|
|
35
|
+
return Reflect.get(apiTarget, apiProperty, apiTarget);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=commandRejection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandRejection.js","sourceRoot":"","sources":["../src/commandRejection.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IACvD,YACW,OAAe,EACf,SAAiB,EACjB,YAAqB;QAE9B,MAAM,MAAM,GAAG,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,iBAAiB,CAAC;QACnF,KAAK,CAAC,yCAAyC,OAAO,MAAM,MAAM,EAAE,CAAC,CAAC;uBAL7D,OAAO;yBACP,SAAS;4BACT,YAAY;QAIrB,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;IAC/C,CAAC;CACF;AAID,SAAS,eAAe,CAAC,OAAuB;IAC9C,OAAO,KAAK,EAAE,GAAG,IAAI,EAAE,EAAE;QACvB,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;QACxC,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;QAClC,mHAAmH;QACnH,IAAK,MAAgC,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;YACxD,MAAM,IAAI,8BAA8B,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;QAC1G,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;AACJ,CAAC;AAED,qHAAqH;AACrH,MAAM,UAAU,0BAA0B,CAAC,MAAc;IACvD,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE;QACvB,GAAG,CAAC,MAAM,EAAE,QAAQ;YAClB,IAAI,QAAQ,KAAK,YAAY,EAAE,CAAC;gBAC9B,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;YAC/C,CAAC;YACD,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC;YAC9B,OAAO,IAAI,KAAK,CAAC,GAAG,EAAE;gBACpB,GAAG,CAAC,SAAS,EAAE,WAAW;oBACxB,IAAI,WAAW,KAAK,oCAAoC,EAAE,CAAC;wBACzD,OAAO,eAAe,CAAC,SAAS,CAAC,kCAAkC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;oBACvF,CAAC;oBACD,OAAO,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;gBACxD,CAAC;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/getTakaro.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTakaro.d.ts","sourceRoot":"","sources":["../src/getTakaro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"getTakaro.d.ts","sourceRoot":"","sources":["../src/getTakaro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE/D,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACzB,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC,EACnE,cAAc,CAAC,EAAE,MAAM,EAEvB,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,aAAa,GAC3D;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAAE,CAmC/C"}
|
package/dist/getTakaro.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Client } from '@takaro/apiclient';
|
|
2
|
+
import { rejectUnsuccessfulCommands } from './commandRejection.js';
|
|
2
3
|
export function getTakaro(data, logger, clientOverride,
|
|
3
4
|
// Sandbox passes its guarded axios, so the GH #4021 caps cover `takaro.*()` too.
|
|
4
5
|
axiosFactory) {
|
|
5
|
-
const
|
|
6
|
+
const rawClient = clientOverride ??
|
|
6
7
|
new Client({
|
|
7
8
|
url: data.url,
|
|
8
9
|
auth: {
|
|
@@ -11,7 +12,8 @@ axiosFactory) {
|
|
|
11
12
|
log: logger ? logger : console,
|
|
12
13
|
axiosFactory,
|
|
13
14
|
});
|
|
14
|
-
|
|
15
|
+
rawClient.setHeader('X-Takaro-Module', data.module.moduleId);
|
|
16
|
+
const takaro = rejectUnsuccessfulCommands(rawClient);
|
|
15
17
|
if (data.pog) {
|
|
16
18
|
const sendPmToPlayer = async (message) => {
|
|
17
19
|
return takaro.gameserver.gameServerControllerSendMessage(data.gameServerId, {
|
package/dist/getTakaro.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTakaro.js","sourceRoot":"","sources":["../src/getTakaro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"getTakaro.js","sourceRoot":"","sources":["../src/getTakaro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAGnE,MAAM,UAAU,SAAS,CACvB,IAAyB,EACzB,MAAmE,EACnE,cAAuB;AACvB,iFAAiF;AACjF,YAA4D;IAE5D,MAAM,SAAS,GACb,cAAc;QACd,IAAI,MAAM,CAAC;YACT,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,IAAI,EAAE;gBACJ,KAAK,EAAE,IAAI,CAAC,KAAK;aAClB;YACD,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;YAC9B,YAAY;SACb,CAAC,CAAC;IAEL,SAAS,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC7D,MAAM,MAAM,GAAG,0BAA0B,CAAC,SAAS,CAAC,CAAC;IAErD,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;QACb,MAAM,cAAc,GAAG,KAAK,EAAE,OAAe,EAAE,EAAE;YAC/C,OAAO,MAAM,CAAC,UAAU,CAAC,+BAA+B,CAAC,IAAI,CAAC,YAAY,EAAE;gBAC1E,OAAO;gBACP,IAAI,EAAE;oBACJ,SAAS,EAAE;wBACT,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM;qBACxB;iBACF;aACF,CAAC,CAAC;QACL,CAAC,CAAC;QAEF,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,cAAc,CAAC;QAE7B,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,cAAc,CAAC;QAClC,CAAC;IACH,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAC1B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takaro/helpers",
|
|
3
3
|
"description": "A collection of helpers, used inside Takaro Functions",
|
|
4
|
-
"version": "0.0.0-dev.
|
|
4
|
+
"version": "0.0.0-dev.3abbd4a",
|
|
5
5
|
"author": "",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@takaro/apiclient": "0.0.0-dev.
|
|
7
|
+
"@takaro/apiclient": "0.0.0-dev.3abbd4a",
|
|
8
8
|
"@types/lodash-es": "4.17.12",
|
|
9
|
-
"axios": "1.21.
|
|
9
|
+
"axios": "1.21.1",
|
|
10
10
|
"croner": "8.1.2",
|
|
11
11
|
"https-proxy-agent": "9.1.0",
|
|
12
|
-
"lodash-es": "4.
|
|
12
|
+
"lodash-es": "4.18.1"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [],
|
|
15
15
|
"license": "ISC",
|