@truelab/trueserver 0.0.4 → 0.0.6

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.
Files changed (132) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/MIGRATION.md +303 -0
  3. package/README.md +96 -98
  4. package/dist/application.d.ts.map +1 -1
  5. package/dist/application.js +9 -5
  6. package/dist/application.js.map +1 -1
  7. package/dist/examples.d.ts +1 -0
  8. package/dist/examples.d.ts.map +1 -1
  9. package/dist/examples.js +3 -1
  10. package/dist/examples.js.map +1 -1
  11. package/dist/helpers/config.helper.d.ts +4 -1
  12. package/dist/helpers/config.helper.d.ts.map +1 -1
  13. package/dist/helpers/config.helper.js +26 -0
  14. package/dist/helpers/config.helper.js.map +1 -1
  15. package/dist/helpers/errors.helper.d.ts +18 -0
  16. package/dist/helpers/errors.helper.d.ts.map +1 -0
  17. package/dist/helpers/errors.helper.js +20 -0
  18. package/dist/helpers/errors.helper.js.map +1 -0
  19. package/dist/helpers/fastify.helper.d.ts +5 -1
  20. package/dist/helpers/fastify.helper.d.ts.map +1 -1
  21. package/dist/helpers/fastify.helper.js +3 -1
  22. package/dist/helpers/fastify.helper.js.map +1 -1
  23. package/dist/helpers/handlers.helper.d.ts +10 -1
  24. package/dist/helpers/handlers.helper.d.ts.map +1 -1
  25. package/dist/helpers/handlers.helper.js +2 -1
  26. package/dist/helpers/handlers.helper.js.map +1 -1
  27. package/dist/index.d.ts +6 -4
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +7 -4
  30. package/dist/index.js.map +1 -1
  31. package/dist/plugins/404.plugin.d.ts.map +1 -1
  32. package/dist/plugins/404.plugin.js +2 -1
  33. package/dist/plugins/404.plugin.js.map +1 -1
  34. package/dist/plugins/apikey.plugin.d.ts.map +1 -1
  35. package/dist/plugins/apikey.plugin.js +6 -7
  36. package/dist/plugins/apikey.plugin.js.map +1 -1
  37. package/dist/plugins/error.plugin.d.ts.map +1 -1
  38. package/dist/plugins/error.plugin.js +6 -2
  39. package/dist/plugins/error.plugin.js.map +1 -1
  40. package/dist/plugins/sentry.plugin.js +2 -2
  41. package/dist/plugins/sentry.plugin.js.map +1 -1
  42. package/dist/plugins/swagger.plugin.d.ts.map +1 -1
  43. package/dist/plugins/swagger.plugin.js +5 -1
  44. package/dist/plugins/swagger.plugin.js.map +1 -1
  45. package/dist/routes/checksum/checksum.route.d.ts +3 -0
  46. package/dist/routes/checksum/checksum.route.d.ts.map +1 -0
  47. package/dist/routes/checksum/checksum.route.js +21 -0
  48. package/dist/routes/checksum/checksum.route.js.map +1 -0
  49. package/dist/routes/checksum/index.d.ts +3 -0
  50. package/dist/routes/checksum/index.d.ts.map +1 -0
  51. package/dist/routes/checksum/index.js +12 -0
  52. package/dist/routes/checksum/index.js.map +1 -0
  53. package/dist/routes/client/client.route.d.ts +3 -0
  54. package/dist/routes/client/client.route.d.ts.map +1 -0
  55. package/dist/routes/{client.route.js → client/client.route.js} +5 -5
  56. package/dist/routes/client/client.route.js.map +1 -0
  57. package/dist/routes/client/index.d.ts +3 -0
  58. package/dist/routes/client/index.d.ts.map +1 -0
  59. package/dist/routes/client/index.js +12 -0
  60. package/dist/routes/client/index.js.map +1 -0
  61. package/dist/routes/config/config.route.js +1 -1
  62. package/dist/routes/config/config.route.js.map +1 -1
  63. package/dist/routes/config/config.route.validate.plugin.d.ts.map +1 -1
  64. package/dist/routes/config/config.route.validate.plugin.js +43 -17
  65. package/dist/routes/config/config.route.validate.plugin.js.map +1 -1
  66. package/dist/routes/play/play.route.validate.plugin.d.ts +9 -9
  67. package/dist/routes/play/play.route.validate.plugin.d.ts.map +1 -1
  68. package/dist/routes/play/play.route.validate.plugin.js +84 -40
  69. package/dist/routes/play/play.route.validate.plugin.js.map +1 -1
  70. package/dist/routes/validate/validate.route.validate.plugin.d.ts.map +1 -1
  71. package/dist/routes/validate/validate.route.validate.plugin.js +9 -3
  72. package/dist/routes/validate/validate.route.validate.plugin.js.map +1 -1
  73. package/dist/routes-public/healthcheck.route.d.ts.map +1 -0
  74. package/dist/{routes → routes-public}/healthcheck.route.js +4 -10
  75. package/dist/routes-public/healthcheck.route.js.map +1 -0
  76. package/dist/schemas/checksum.schema.d.ts +11 -0
  77. package/dist/schemas/checksum.schema.d.ts.map +1 -0
  78. package/dist/schemas/checksum.schema.js +26 -0
  79. package/dist/schemas/checksum.schema.js.map +1 -0
  80. package/dist/schemas/client.schema.d.ts +1 -1
  81. package/dist/schemas/client.schema.js +4 -4
  82. package/dist/schemas/client.schema.js.map +1 -1
  83. package/dist/schemas/config.schema.d.ts +17 -20
  84. package/dist/schemas/config.schema.d.ts.map +1 -1
  85. package/dist/schemas/config.schema.js +41 -42
  86. package/dist/schemas/config.schema.js.map +1 -1
  87. package/dist/schemas/examples/checksum.schema.examples.d.ts +3 -0
  88. package/dist/schemas/examples/checksum.schema.examples.d.ts.map +1 -0
  89. package/dist/schemas/examples/checksum.schema.examples.js +26 -0
  90. package/dist/schemas/examples/checksum.schema.examples.js.map +1 -0
  91. package/dist/schemas/examples/client.schema.examples.d.ts.map +1 -1
  92. package/dist/schemas/examples/client.schema.examples.js +15 -18
  93. package/dist/schemas/examples/client.schema.examples.js.map +1 -1
  94. package/dist/schemas/examples/config.schema.examples.d.ts.map +1 -1
  95. package/dist/schemas/examples/config.schema.examples.js +30 -34
  96. package/dist/schemas/examples/config.schema.examples.js.map +1 -1
  97. package/dist/schemas/examples/healthcheck.schema.examples.d.ts.map +1 -1
  98. package/dist/schemas/examples/healthcheck.schema.examples.js +3 -14
  99. package/dist/schemas/examples/healthcheck.schema.examples.js.map +1 -1
  100. package/dist/schemas/examples/play.schema.examples.d.ts.map +1 -1
  101. package/dist/schemas/examples/play.schema.examples.js +66 -130
  102. package/dist/schemas/examples/play.schema.examples.js.map +1 -1
  103. package/dist/schemas/examples/validate.schema.examples.d.ts.map +1 -1
  104. package/dist/schemas/examples/validate.schema.examples.js +1 -3
  105. package/dist/schemas/examples/validate.schema.examples.js.map +1 -1
  106. package/dist/schemas/healthcheck.schema.d.ts +2 -20
  107. package/dist/schemas/healthcheck.schema.d.ts.map +1 -1
  108. package/dist/schemas/healthcheck.schema.js +10 -41
  109. package/dist/schemas/healthcheck.schema.js.map +1 -1
  110. package/dist/schemas/play.schema.d.ts +21 -16
  111. package/dist/schemas/play.schema.d.ts.map +1 -1
  112. package/dist/schemas/play.schema.js +36 -45
  113. package/dist/schemas/play.schema.js.map +1 -1
  114. package/dist/schemas/shared.d.ts +13 -21
  115. package/dist/schemas/shared.d.ts.map +1 -1
  116. package/dist/schemas/shared.js +56 -72
  117. package/dist/schemas/shared.js.map +1 -1
  118. package/dist/schemas/validate.schema.d.ts +2 -3
  119. package/dist/schemas/validate.schema.d.ts.map +1 -1
  120. package/dist/schemas/validate.schema.js +2 -5
  121. package/dist/schemas/validate.schema.js.map +1 -1
  122. package/package.json +3 -2
  123. package/dist/plugins/metrics.plugin.d.ts +0 -9
  124. package/dist/plugins/metrics.plugin.d.ts.map +0 -1
  125. package/dist/plugins/metrics.plugin.js +0 -24
  126. package/dist/plugins/metrics.plugin.js.map +0 -1
  127. package/dist/routes/client.route.d.ts +0 -3
  128. package/dist/routes/client.route.d.ts.map +0 -1
  129. package/dist/routes/client.route.js.map +0 -1
  130. package/dist/routes/healthcheck.route.d.ts.map +0 -1
  131. package/dist/routes/healthcheck.route.js.map +0 -1
  132. /package/dist/{routes → routes-public}/healthcheck.route.d.ts +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../routes/checksum/index.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,aAAa,mFAEjB,CAAA;AAEF,eAAe,aAAa,CAAA"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fastify_helper_1 = require("../../helpers/fastify.helper");
7
+ const checksum_route_1 = __importDefault(require("./checksum.route"));
8
+ const checksumRoute = (0, fastify_helper_1.registerRoute)(async (fastify) => {
9
+ fastify.register(checksum_route_1.default);
10
+ });
11
+ exports.default = checksumRoute;
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../routes/checksum/index.ts"],"names":[],"mappings":";;;;;AAAA,iEAA4D;AAC5D,sEAAoD;AAEpD,MAAM,aAAa,GAAG,IAAA,8BAAa,EAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IAClD,OAAO,CAAC,QAAQ,CAAC,wBAAqB,CAAC,CAAA;AAC3C,CAAC,CAAC,CAAA;AAEF,kBAAe,aAAa,CAAA"}
@@ -0,0 +1,3 @@
1
+ declare const clientRoute: (fastify: import("../../helpers/fastify.helper").FastifyTypebox) => Promise<void>;
2
+ export default clientRoute;
3
+ //# sourceMappingURL=client.route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.route.d.ts","sourceRoot":"","sources":["../../../routes/client/client.route.ts"],"names":[],"mappings":"AAOA,QAAA,MAAM,WAAW,mFAYf,CAAA;AAEF,eAAe,WAAW,CAAA"}
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const fastify_helper_1 = require("../helpers/fastify.helper");
4
- const handlers_helper_1 = require("../helpers/handlers.helper");
5
- const client_schema_1 = require("../schemas/client.schema");
6
- const shared_1 = require("../schemas/shared");
3
+ const fastify_helper_1 = require("../../helpers/fastify.helper");
4
+ const handlers_helper_1 = require("../../helpers/handlers.helper");
5
+ const client_schema_1 = require("../../schemas/client.schema");
6
+ const shared_1 = require("../../schemas/shared");
7
7
  const clientRoute = (0, fastify_helper_1.registerRoute)(async (fastify) => {
8
- fastify.post('/client', {
8
+ fastify.get('/client', {
9
9
  schema: {
10
10
  response: {
11
11
  200: client_schema_1.ClientReplySchema,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.route.js","sourceRoot":"","sources":["../../../routes/client/client.route.ts"],"names":[],"mappings":";;AAAA,iEAA4D;AAC5D,mEAAwD;AACxD,+DAA+D;AAC/D,iDAE6B;AAE7B,MAAM,WAAW,GAAG,IAAA,8BAAa,EAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IAChD,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE;QACnB,MAAM,EAAE;YACJ,QAAQ,EAAE;gBACN,GAAG,EAAE,iCAAiB;gBACtB,GAAG,EAAE,2BAAkB;gBACvB,GAAG,EAAE,0BAAiB;gBACtB,GAAG,EAAE,4BAAmB;aAC3B;YACD,OAAO,EAAE,sBAAa;SACzB;KACJ,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,0BAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAA;AACtF,CAAC,CAAC,CAAA;AAEF,kBAAe,WAAW,CAAA"}
@@ -0,0 +1,3 @@
1
+ declare const clientRoute: (fastify: import("../../helpers/fastify.helper").FastifyTypebox) => Promise<void>;
2
+ export default clientRoute;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../routes/client/index.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,WAAW,mFAEf,CAAA;AAEF,eAAe,WAAW,CAAA"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fastify_helper_1 = require("../../helpers/fastify.helper");
7
+ const client_route_1 = __importDefault(require("./client.route"));
8
+ const clientRoute = (0, fastify_helper_1.registerRoute)(async (fastify) => {
9
+ fastify.register(client_route_1.default);
10
+ });
11
+ exports.default = clientRoute;
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../routes/client/index.ts"],"names":[],"mappings":";;;;;AAAA,iEAA4D;AAC5D,kEAAgD;AAEhD,MAAM,WAAW,GAAG,IAAA,8BAAa,EAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IAChD,OAAO,CAAC,QAAQ,CAAC,sBAAmB,CAAC,CAAA;AACzC,CAAC,CAAC,CAAA;AAEF,kBAAe,WAAW,CAAA"}
@@ -5,7 +5,7 @@ const handlers_helper_1 = require("../../helpers/handlers.helper");
5
5
  const config_schema_1 = require("../../schemas/config.schema");
6
6
  const shared_1 = require("../../schemas/shared");
7
7
  const configRouteOriginal = (0, fastify_helper_1.registerRoute)(async (fastify) => {
8
- fastify.post('/config', {
8
+ fastify.get('/config', {
9
9
  schema: {
10
10
  response: {
11
11
  200: config_schema_1.ConfigReplySchema,
@@ -1 +1 @@
1
- {"version":3,"file":"config.route.js","sourceRoot":"","sources":["../../../routes/config/config.route.ts"],"names":[],"mappings":";;AAAA,iEAA4D;AAC5D,mEAAwD;AACxD,+DAA+D;AAC/D,iDAE6B;AAE7B,MAAM,mBAAmB,GAAG,IAAA,8BAAa,EAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACxD,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE;QACpB,MAAM,EAAE;YACJ,QAAQ,EAAE;gBACN,GAAG,EAAE,iCAAiB;gBACtB,GAAG,EAAE,2BAAkB;gBACvB,GAAG,EAAE,0BAAiB;gBACtB,GAAG,EAAE,4BAAmB;aAC3B;YACD,OAAO,EAAE,sBAAa;SACzB;KACJ,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,0BAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAA;AACtF,CAAC,CAAC,CAAA;AAEF,kBAAe,mBAAmB,CAAA"}
1
+ {"version":3,"file":"config.route.js","sourceRoot":"","sources":["../../../routes/config/config.route.ts"],"names":[],"mappings":";;AAAA,iEAA4D;AAC5D,mEAAwD;AACxD,+DAA+D;AAC/D,iDAE6B;AAE7B,MAAM,mBAAmB,GAAG,IAAA,8BAAa,EAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACxD,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE;QACnB,MAAM,EAAE;YACJ,QAAQ,EAAE;gBACN,GAAG,EAAE,iCAAiB;gBACtB,GAAG,EAAE,2BAAkB;gBACvB,GAAG,EAAE,0BAAiB;gBACtB,GAAG,EAAE,4BAAmB;aAC3B;YACD,OAAO,EAAE,sBAAa;SACzB;KACJ,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,0BAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAA;AACtF,CAAC,CAAC,CAAA;AAEF,kBAAe,mBAAmB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"config.route.validate.plugin.d.ts","sourceRoot":"","sources":["../../../routes/config/config.route.validate.plugin.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,yBAAyB,mFA2C7B,CAAA;AAEF,eAAe,yBAAyB,CAAA"}
1
+ {"version":3,"file":"config.route.validate.plugin.d.ts","sourceRoot":"","sources":["../../../routes/config/config.route.validate.plugin.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,yBAAyB,mFAiE7B,CAAA;AAEF,eAAe,yBAAyB,CAAA"}
@@ -1,38 +1,64 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const config_helper_1 = require("../../helpers/config.helper");
4
+ const errors_helper_1 = require("../../helpers/errors.helper");
4
5
  const fastify_helper_1 = require("../../helpers/fastify.helper");
5
- const shared_1 = require("../../schemas/shared");
6
6
  const configRouteValidatePlugin = (0, fastify_helper_1.registerPlugin)(async (fastify) => {
7
7
  const gameConfig = (0, config_helper_1.getGameConfig)();
8
- fastify.addHook('preSerialization', (_request, _reply, payload, done) => {
9
- if (payload?.ok) {
8
+ fastify.addHook('preSerialization', (request, _reply, payload, done) => {
9
+ if (payload?.gameId) {
10
10
  try {
11
11
  payload.stakeModes.forEach((stakeMode) => {
12
- if (!gameConfig.hasBuy
13
- && ([shared_1.EStakeType.buy, shared_1.EStakeType.bonusBet].includes(stakeMode.type))) {
14
- throw new Error(`Game doesn't support buyable stake modes ("${stakeMode.name}")`);
15
- }
16
12
  if (stakeMode.multiple && stakeMode.maxQty === undefined) {
17
- throw new Error(`Property "maxQty" should be defined for the stake mode ("${stakeMode.name}")`);
13
+ throw new Error(`Property "maxQty" should be defined for the multiple stake mode "${stakeMode.name}"`);
18
14
  }
19
15
  if (!stakeMode.multiple && stakeMode.maxQty !== undefined) {
20
- throw new Error(`Stake mode ("${stakeMode.name}") should be multiple`);
16
+ throw new Error(`Stake mode "${stakeMode.name}" should be multiple to define "maxQty"`);
21
17
  }
22
18
  });
23
- if (payload.coinRatio === undefined && payload.variableLevels === undefined) {
24
- throw new Error('coinRatio or variableLevels should be defined');
19
+ if (payload.hasChoice && !payload.hasMeta) {
20
+ throw new Error('hasChoice=true requires hasMeta=true');
21
+ }
22
+ if (payload.hasVariableLines) {
23
+ if (!Array.isArray(payload.variableLevels) || payload.variableLevels.length === 0) {
24
+ throw new Error('variableLevels must be a non-empty array when hasVariableLines=true');
25
+ }
26
+ if (payload.defaultLevel === undefined || !payload.variableLevels.includes(payload.defaultLevel)) {
27
+ throw new Error('defaultLevel must be one of variableLevels when hasVariableLines=true');
28
+ }
29
+ if (payload.coinRatio !== undefined) {
30
+ throw new Error('coinRatio must not be set when hasVariableLines=true');
31
+ }
32
+ }
33
+ else {
34
+ if (payload.coinRatio === undefined) {
35
+ throw new Error('coinRatio is required when hasVariableLines=false');
36
+ }
37
+ if (payload.variableLevels !== undefined || payload.defaultLevel !== undefined) {
38
+ throw new Error('variableLevels/defaultLevel must not be set when hasVariableLines=false');
39
+ }
40
+ }
41
+ if (payload.gameId !== gameConfig.gameId) {
42
+ throw new Error('gameId in reply must match gameConfig.gameId');
43
+ }
44
+ if (payload.gameTitle !== gameConfig.gameTitle) {
45
+ throw new Error('gameTitle in reply must match gameConfig.gameTitle');
46
+ }
47
+ if (payload.rtpVersion !== gameConfig.rtpVersion) {
48
+ throw new Error(`rtpVersion in reply ("${payload.rtpVersion}") must match gameConfig.rtpVersion ("${gameConfig.rtpVersion}")`);
25
49
  }
26
- if (payload.coinRatio !== undefined && payload.variableLevels !== undefined) {
27
- throw new Error('coinRatio and variableLevels must not be defined together');
50
+ const pathParams = request.params;
51
+ if (pathParams?.rtpVersion !== undefined && payload.rtpVersion !== pathParams.rtpVersion) {
52
+ throw new Error(`rtpVersion in reply ("${payload.rtpVersion}") must match the {rtpVersion} path segment ("${pathParams.rtpVersion}")`);
28
53
  }
29
- if ((payload.coinRatio !== gameConfig.coinRatio)
30
- || (payload.variableLevels !== gameConfig.variableLevels)) {
31
- throw new Error('coinRatio or variableLevels should be equal in gameConfig and in the handler');
54
+ if (payload.coinRatio !== gameConfig.coinRatio
55
+ || JSON.stringify(payload.variableLevels) !== JSON.stringify(gameConfig.variableLevels)
56
+ || payload.defaultLevel !== gameConfig.defaultLevel) {
57
+ throw new Error('coinRatio / variableLevels / defaultLevel must be equal in gameConfig and in the handler');
32
58
  }
33
59
  }
34
60
  catch (error) {
35
- throw (0, fastify_helper_1.httpError)(`Advanced validation failed: ${error.message}`, 500);
61
+ throw (0, fastify_helper_1.httpError)(`Advanced validation failed: ${error.message}`, 500, errors_helper_1.EErrorCode.ValidationConfig);
36
62
  }
37
63
  }
38
64
  done(null, payload);
@@ -1 +1 @@
1
- {"version":3,"file":"config.route.validate.plugin.js","sourceRoot":"","sources":["../../../routes/config/config.route.validate.plugin.ts"],"names":[],"mappings":";;AAAA,+DAA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AAC,cAAc,KAAK,SAAS,EAAE,CAAC;oBAC1E,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;gBAChF,CAAC;gBAED,IACI,CAAC,OAAO,CAAC,SAAS,KAAK,UAAU,CAAC,SAAS,CAAC;uBACzC,CAAC,OAAO,CAAC,cAAc,KAAK,UAAU,CAAC,cAAc,CAAC,EAC3D,CAAC;oBACC,MAAM,IAAI,KAAK,CAAC,8EAA8E,CAAC,CAAA;gBACnG,CAAC;YACL,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,MAAM,IAAA,0BAAS,EAAC,+BAA+B,KAAK,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,CAAA;YACxE,CAAC;QACL,CAAC;QAED,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IACvB,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA;AAEF,kBAAe,yBAAyB,CAAA"}
1
+ {"version":3,"file":"config.route.validate.plugin.js","sourceRoot":"","sources":["../../../routes/config/config.route.validate.plugin.ts"],"names":[],"mappings":";;AAAA,+DAA2D;AAC3D,+DAAwD;AACxD,iEAAwE;AAIxE,MAAM,yBAAyB,GAAG,IAAA,+BAAc,EAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IAC/D,MAAM,UAAU,GAAG,IAAA,6BAAa,GAAE,CAAA;IAElC,OAAO,CAAC,OAAO,CAAe,kBAAkB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QACjF,IAAI,OAAO,EAAE,MAAM,EAAE,CAAC;YAClB,IAAI,CAAC;gBACD,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;oBACrC,IAAI,SAAS,CAAC,QAAQ,IAAI,SAAS,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;wBACvD,MAAM,IAAI,KAAK,CAAC,oEAAoE,SAAS,CAAC,IAAI,GAAG,CAAC,CAAA;oB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CAAC,CAAA;AACN,CAAC,CAAC,CAAA;AAEF,kBAAe,yBAAyB,CAAA"}
@@ -1,13 +1,13 @@
1
1
  import { TGameConfig } from '../../helpers/config.helper';
2
- import { TStake, TStakeMode } from '../../schemas/shared';
3
- export declare function validateStakes(stakes: TStake[], gameConfig: TGameConfig, stakesMap: Map<string, TStakeMode>): void;
4
- export declare function validateTestData(testData: string): void;
5
- export declare function validateChoice(choice: number, gameConfig: TGameConfig): void;
6
- export declare function validateMeta(metaPrivate: string, metaPublic: string, gameConfig: TGameConfig): void;
7
- export declare function validateGamble(isGambleAllowed: boolean, gameConfig: TGameConfig): void;
8
- export declare function validateFinishedInReply(finished: boolean, gameConfig: TGameConfig): void;
9
- export declare function validateChoicesInReply(choices: number[], gameConfig: TGameConfig): void;
10
- export declare function validateMetaInReply(metaPrivate: string, metaPublic: string, gameConfig: TGameConfig): void;
2
+ import { TMeta, TStake, TStakeMode } from '../../schemas/shared';
3
+ export declare function validateStakes(stakes: TStake[] | undefined, gameConfig: TGameConfig, stakesMap: Map<string, TStakeMode>): void;
4
+ export declare function validateTestData(testData: string | undefined): void;
5
+ export declare function validateStepIndexConsistency(stepIndex: number, stakes: TStake[] | undefined, choice: number | undefined, gameConfig: TGameConfig): void;
6
+ export declare function validateChoice(choice: number | undefined, gameConfig: TGameConfig): void;
7
+ export declare function validateMeta(meta: TMeta | undefined, gameConfig: TGameConfig): void;
8
+ export declare function validateFinishedInReply(finished: boolean, choices: number[] | undefined, gameConfig: TGameConfig): void;
9
+ export declare function validateChoicesInReply(choices: number[] | undefined, gameConfig: TGameConfig): void;
10
+ export declare function validateMetaInReply(meta: TMeta | undefined, gameConfig: TGameConfig): void;
11
11
  declare const playRouteValidatePlugin: (fastify: import("../../helpers/fastify.helper").FastifyTypebox) => Promise<void>;
12
12
  export default playRouteValidatePlugin;
13
13
  //# sourceMappingURL=play.route.validate.plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"play.route.validate.plugin.d.ts","sourceRoot":"","sources":["../../../routes/play/play.route.validate.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAIxE,OAAO,EAAiB,MAAM,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAExE,wBAAgB,cAAc,CAC1B,MAAM,EAAE,MAAM,EAAE,EAChB,UAAU,EAAE,WAAW,EACvB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,QAiCrC;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,QAIhD;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,QAIrE;AAED,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,QAI5F;AAED,wBAAgB,cAAc,CAAC,eAAe,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,QAI/E;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,QAIjF;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,WAAW,QAIhF;AAED,wBAAgB,mBAAmB,CAC/B,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,WAAW,QAK1B;AAED,QAAA,MAAM,uBAAuB,mFAkC3B,CAAA;AAEF,eAAe,uBAAuB,CAAA"}
1
+ {"version":3,"file":"play.route.validate.plugin.d.ts","sourceRoot":"","sources":["../../../routes/play/play.route.validate.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAKxE,OAAO,EACH,KAAK,EAAiB,MAAM,EAAE,UAAU,EAC3C,MAAM,sBAAsB,CAAA;AAW7B,wBAAgB,cAAc,CAC1B,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,EAC5B,UAAU,EAAE,WAAW,EACvB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,QAkDrC;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,QAI5D;AAED,wBAAgB,4BAA4B,CACxC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,EAC5B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,UAAU,EAAE,WAAW,QAiB1B;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,UAAU,EAAE,WAAW,QAIjF;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,KAAK,GAAG,SAAS,EAAE,UAAU,EAAE,WAAW,QAI5E;AAED,wBAAgB,uBAAuB,CACnC,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,MAAM,EAAE,GAAG,SAAS,EAC7B,UAAU,EAAE,WAAW,QAW1B;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,UAAU,EAAE,WAAW,QAO5F;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,KAAK,GAAG,SAAS,EAAE,UAAU,EAAE,WAAW,QAInF;AAED,QAAA,MAAM,uBAAuB,mFAoC3B,CAAA;AAEF,eAAe,uBAAuB,CAAA"}
@@ -2,103 +2,147 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateStakes = validateStakes;
4
4
  exports.validateTestData = validateTestData;
5
+ exports.validateStepIndexConsistency = validateStepIndexConsistency;
5
6
  exports.validateChoice = validateChoice;
6
7
  exports.validateMeta = validateMeta;
7
- exports.validateGamble = validateGamble;
8
8
  exports.validateFinishedInReply = validateFinishedInReply;
9
9
  exports.validateChoicesInReply = validateChoicesInReply;
10
10
  exports.validateMetaInReply = validateMetaInReply;
11
11
  const config_helper_1 = require("../../helpers/config.helper");
12
12
  const env_helper_1 = require("../../helpers/env.helper");
13
+ const errors_helper_1 = require("../../helpers/errors.helper");
13
14
  const fastify_helper_1 = require("../../helpers/fastify.helper");
15
+ class CodedError extends Error {
16
+ code;
17
+ constructor(message, code) {
18
+ super(message);
19
+ this.code = code;
20
+ }
21
+ }
14
22
  function validateStakes(stakes, gameConfig, stakesMap) {
15
23
  if (stakes === undefined)
16
24
  return;
17
25
  if (gameConfig.hasMultiStake === false && stakes.length > 1) {
18
- throw new Error('Multiple stakes are not allowed');
26
+ throw new CodedError('Multiple stakes are not allowed', errors_helper_1.EErrorCode.ValidationStakes);
19
27
  }
28
+ const seenNames = new Set();
20
29
  stakes.forEach((stake) => {
21
- if (!stakesMap.has(stake.name)) {
22
- throw new Error(`Unknown stake name "${stake.name}"`);
30
+ if (seenNames.has(stake.name)) {
31
+ throw new CodedError(`Duplicate stake name "${stake.name}" — each stake must have a unique name`, errors_helper_1.EErrorCode.ValidationStakes);
32
+ }
33
+ seenNames.add(stake.name);
34
+ const stakeMode = stakesMap.get(stake.name);
35
+ if (!stakeMode) {
36
+ throw new CodedError(`Unknown stake name "${stake.name}"`, errors_helper_1.EErrorCode.ValidationStakes);
37
+ }
38
+ if (!stakeMode.multiple && stake.qty !== undefined) {
39
+ throw new CodedError(`Stake "${stake.name}" is not multiple. "qty" property is not allowed`, errors_helper_1.EErrorCode.ValidationStakes);
40
+ }
41
+ if (stakeMode.multiple && stakeMode.maxQty !== undefined && stake.qty !== undefined && stake.qty > stakeMode.maxQty) {
42
+ throw new CodedError(`Stake "${stake.name}" exceeds maxQty=${stakeMode.maxQty}`, errors_helper_1.EErrorCode.ValidationStakes);
23
43
  }
24
- if (!stakesMap.get(stake.name).multiple && stake.qty !== undefined) {
25
- throw new Error(`Stake "${stake.name}" is not multiple. "qty" property is not allowed`);
44
+ if (!gameConfig.hasVariableLines && stake.level !== undefined) {
45
+ throw new CodedError('Variable levels are not allowed when hasVariableLines=false', errors_helper_1.EErrorCode.ValidationStakes);
26
46
  }
27
- if (gameConfig.variableLevels === undefined && stake.level !== undefined) {
28
- throw new Error('Variable levels are not allowed');
47
+ if (gameConfig.hasVariableLines && stake.level === undefined) {
48
+ throw new CodedError('"level" is required in stakes when hasVariableLines=true', errors_helper_1.EErrorCode.ValidationStakes);
29
49
  }
30
- if (gameConfig.variableLevels !== undefined && stake.level === undefined) {
31
- throw new Error('Variable levels are required in stakes');
50
+ if (gameConfig.hasVariableLines && !gameConfig.variableLevels.includes(stake.level)) {
51
+ throw new CodedError(`Stake "${stake.name}" level=${stake.level} is not in variableLevels`, errors_helper_1.EErrorCode.ValidationStakes);
32
52
  }
33
- if (!stakesMap.get(stake.name).parametric && stake.params !== undefined) {
34
- throw new Error(`Stake "${stake.name}" is not parametric. "params" property is not allowed`);
53
+ if (!stakeMode.parametric && stake.params !== undefined) {
54
+ throw new CodedError(`Stake "${stake.name}" is not parametric. "params" property is not allowed`, errors_helper_1.EErrorCode.ValidationStakes);
35
55
  }
36
- if (stakesMap.get(stake.name).parametric && stake.params === undefined) {
37
- throw new Error(`Stake "${stake.name}" is parametric. "params" property is required`);
56
+ if (stakeMode.parametric && stake.params === undefined) {
57
+ throw new CodedError(`Stake "${stake.name}" is parametric. "params" property is required`, errors_helper_1.EErrorCode.ValidationStakes);
38
58
  }
39
59
  });
40
60
  }
41
61
  function validateTestData(testData) {
42
62
  if ((0, env_helper_1.variation)(false, false, true) && testData !== undefined) {
43
- throw new Error('Test data is not allowed on production environment');
63
+ throw new CodedError('Test data is not allowed on production environment', errors_helper_1.EErrorCode.ValidationTest);
44
64
  }
45
65
  }
46
- function validateChoice(choice, gameConfig) {
47
- if (!gameConfig.hasChoice && choice !== undefined) {
48
- throw new Error('The game is not stepped. Choice is not allowed');
66
+ function validateStepIndexConsistency(stepIndex, stakes, choice, gameConfig) {
67
+ if (stepIndex === 0) {
68
+ if (stakes === undefined) {
69
+ throw new CodedError('"stakes" is required on the opening step (stepIndex=0)', errors_helper_1.EErrorCode.ValidationStakes);
70
+ }
71
+ if (choice !== undefined) {
72
+ throw new CodedError('"choice" is not allowed on the opening step (stepIndex=0)', errors_helper_1.EErrorCode.ValidationChoice);
73
+ }
74
+ }
75
+ else {
76
+ if (stakes !== undefined) {
77
+ throw new CodedError('"stakes" is allowed only on the opening step (stepIndex=0)', errors_helper_1.EErrorCode.ValidationStakes);
78
+ }
79
+ if (gameConfig.hasChoice && choice === undefined) {
80
+ throw new CodedError('"choice" is required on continuation steps (stepIndex > 0)', errors_helper_1.EErrorCode.ValidationChoice);
81
+ }
49
82
  }
50
83
  }
51
- function validateMeta(metaPrivate, metaPublic, gameConfig) {
52
- if (!gameConfig.hasMeta && (metaPrivate !== undefined || metaPublic !== undefined)) {
53
- throw new Error('The game is not supported meta data. metaPrivate and metaPublic are not allowed');
84
+ function validateChoice(choice, gameConfig) {
85
+ if (!gameConfig.hasChoice && choice !== undefined) {
86
+ throw new CodedError('The game is not stepped. "choice" is not allowed', errors_helper_1.EErrorCode.ValidationChoice);
54
87
  }
55
88
  }
56
- function validateGamble(isGambleAllowed, gameConfig) {
57
- if (!gameConfig.hasGamble && isGambleAllowed) {
58
- throw new Error('The game is not supported gamble feature');
89
+ function validateMeta(meta, gameConfig) {
90
+ if (!gameConfig.hasMeta && meta !== undefined) {
91
+ throw new CodedError('The game does not support meta data. "meta" is not allowed', errors_helper_1.EErrorCode.ValidationMeta);
59
92
  }
60
93
  }
61
- function validateFinishedInReply(finished, gameConfig) {
94
+ function validateFinishedInReply(finished, choices, gameConfig) {
62
95
  if (!gameConfig.hasChoice && !finished) {
63
- throw new Error('The game is not stepped. Round should be finished');
96
+ throw new CodedError('The game is not stepped. Round should be finished', errors_helper_1.EErrorCode.BusinessFinishedMismatch);
97
+ }
98
+ if (finished && choices !== undefined) {
99
+ throw new CodedError('"choices" must be absent when results.finished=true', errors_helper_1.EErrorCode.BusinessChoicesMismatch);
100
+ }
101
+ if (!finished && gameConfig.hasChoice && (choices === undefined || choices.length === 0)) {
102
+ throw new CodedError('"choices" must be a non-empty array when results.finished=false', errors_helper_1.EErrorCode.BusinessChoicesMismatch);
64
103
  }
65
104
  }
66
105
  function validateChoicesInReply(choices, gameConfig) {
67
106
  if (!gameConfig.hasChoice && choices !== undefined) {
68
- throw new Error('The game is not stepped. No choices!');
107
+ throw new CodedError('The game is not stepped. results.choices must be absent', errors_helper_1.EErrorCode.BusinessChoicesMismatch);
108
+ }
109
+ if (choices !== undefined && choices.length === 0) {
110
+ throw new CodedError('results.choices must be a non-empty array (never [] or null)', errors_helper_1.EErrorCode.BusinessChoicesMismatch);
69
111
  }
70
112
  }
71
- function validateMetaInReply(metaPrivate, metaPublic, gameConfig) {
72
- if (!gameConfig.hasMeta && (metaPrivate !== undefined || metaPublic !== undefined)) {
73
- throw new Error('The game doesn\'t have meta data. metaPrivate and metaPublic are not allowed');
113
+ function validateMetaInReply(meta, gameConfig) {
114
+ if (!gameConfig.hasMeta && meta !== undefined) {
115
+ throw new CodedError('The game does not have meta data. results.meta is not allowed', errors_helper_1.EErrorCode.ValidationMeta);
74
116
  }
75
117
  }
76
118
  const playRouteValidatePlugin = (0, fastify_helper_1.registerPlugin)(async (fastify) => {
77
119
  const gameConfig = (0, config_helper_1.getGameConfig)();
78
120
  const stakesMap = new Map(gameConfig.stakeModes.map((stakeMode) => [stakeMode.name, stakeMode]));
79
- fastify.addHook('preHandler', (request, reply, done) => {
121
+ fastify.addHook('preHandler', (request, _reply, done) => {
80
122
  const { body } = request;
81
123
  try {
82
124
  validateStakes(body.stakes, gameConfig, stakesMap);
83
125
  validateTestData(body.test);
84
126
  validateChoice(body.choice, gameConfig);
85
- validateMeta(body.metaPrivate, body.metaPublic, gameConfig);
86
- validateGamble(body.isGambleAllowed, gameConfig);
127
+ validateMeta(body.meta, gameConfig);
128
+ validateStepIndexConsistency(body.stepIndex, body.stakes, body.choice, gameConfig);
87
129
  done();
88
130
  }
89
131
  catch (error) {
90
- throw (0, fastify_helper_1.httpError)(`Advanced validation failed: ${error.message}`, 400);
132
+ const code = error instanceof CodedError ? error.code : errors_helper_1.EErrorCode.ValidationBody;
133
+ throw (0, fastify_helper_1.httpError)(`Advanced validation failed: ${error.message}`, 400, code);
91
134
  }
92
135
  });
93
- fastify.addHook('preSerialization', (_request, reply, payload, done) => {
94
- if (payload?.ok) {
136
+ fastify.addHook('preSerialization', (_request, _reply, payload, done) => {
137
+ if (payload?.results) {
95
138
  try {
96
- validateFinishedInReply(payload.finished, gameConfig);
97
- validateChoicesInReply(payload.choices, gameConfig);
98
- validateMetaInReply(payload.metaPrivate, payload.metaPublic, gameConfig);
139
+ validateFinishedInReply(payload.results.finished, payload.results.choices, gameConfig);
140
+ validateChoicesInReply(payload.results.choices, gameConfig);
141
+ validateMetaInReply(payload.results.meta, gameConfig);
99
142
  }
100
143
  catch (error) {
101
- throw (0, fastify_helper_1.httpError)(`Advanced validation failed: ${error.message}`, 500);
144
+ const code = error instanceof CodedError ? error.code : errors_helper_1.EErrorCode.Unhandled;
145
+ throw (0, fastify_helper_1.httpError)(`Advanced validation failed: ${error.message}`, 500, code);
102
146
  }
103
147
  }
104
148
  done(null, payload);
@@ -1 +1 @@
1
- {"version":3,"file":"play.route.validate.plugin.js","sourceRoot":"","sources":["../../../routes/play/play.route.validate.plugin.ts"],"names":[],"mappings":";;AAMA,wCAoCC;AAED,4CAIC;AAED,wCAIC;AAED,oCAIC;AAED,wCAIC;AAED,0DAIC;AAED,wDAIC;AAED,kDAQC;AAxFD,+DAAwE;AACxE,yDAAoD;AACpD,iEAAwE;AAIxE,SAAgB,cAAc,CAC1B,MAAgB,EAChB,UAAuB,EACvB,SAAkC;IAElC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAM;IAEhC,IAAI,UAAU,CAAC,aAAa,KAAK,KAAK,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;IACtD,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACrB,IA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C;YACd,IAAI,CAAC;gBACD,uBAAuB,CAAC,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;gBACrD,sBAAsB,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;gBACnD,mBAAmB,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;YAC5E,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,MAAM,IAAA,0BAAS,EAAC,+BAA+B,KAAK,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,CAAA;YACxE,CAAC;QACL,CAAC;QAED,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IACvB,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA;AAEF,kBAAe,uBAAuB,CAAA"}
1
+ {"version":3,"file":"play.route.validate.plugin.js","sourceRoot":"","sources":["../../../routes/play/play.route.validate.plugin.ts"],"names":[],"mappings":";;AAkBA,wCAqDC;AAED,4CAIC;AAED,oEAqBC;AAED,wCAIC;AAED,oCAIC;AAED,0DAcC;AAED,wDAOC;AAED,kDAIC;AA/ID,+DAAwE;AACxE,yDAAoD;AACpD,+DAAoE;AACpE,iEAAwE;AAMxE,MAAM,UAAW,SAAQ,KAAK;IAC1B,IAAI,CAAY;IAEhB,YAAY,OAAe,EAAE,IAAgB;QACzC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IACpB,CAAC;CACJ;AAED,SAAgB,cAAc,CAC1B,MAA4B,EAC5B,UAAuB,EACvB,SAAkC;IAElC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAM;IAEhC,IAAI,UAAU,CAAC,aAAa,KAAK,KAAK,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1D,MAAM,IAAI,UAAU,CAAC,iCAAiC,EAAE,0BAAU,CAAC,gBAAgB,CAAC,CAAA;IACxF,CAAC;IAED,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,EAAE,UAAU,CAAC,CAAA;gBAC3D,mBAAmB,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;YACzD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,MAAM,IAAI,GAAG,KAAK,YAAY,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,0BAAU,CAAC,SAAS,CAAA;gBAC5E,MAAM,IAAA,0BAAS,EAAC,+BAA+B,KAAK,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;YAC9E,CAAC;QACL,CAAC;QAED,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IACvB,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA;AAEF,kBAAe,uBAAuB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"validate.route.validate.plugin.d.ts","sourceRoot":"","sources":["../../../routes/validate/validate.route.validate.plugin.ts"],"names":[],"mappings":"AAWA,QAAA,MAAM,2BAA2B,mFAkB/B,CAAA;AAEF,eAAe,2BAA2B,CAAA"}
1
+ {"version":3,"file":"validate.route.validate.plugin.d.ts","sourceRoot":"","sources":["../../../routes/validate/validate.route.validate.plugin.ts"],"names":[],"mappings":"AAkBA,QAAA,MAAM,2BAA2B,mFAkB/B,CAAA;AAEF,eAAe,2BAA2B,CAAA"}
@@ -1,11 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const config_helper_1 = require("../../helpers/config.helper");
4
+ const errors_helper_1 = require("../../helpers/errors.helper");
4
5
  const fastify_helper_1 = require("../../helpers/fastify.helper");
5
6
  const play_route_validate_plugin_1 = require("../play/play.route.validate.plugin");
6
7
  function validateAccessibility(gameConfig) {
7
8
  if (!gameConfig.hasValidation) {
8
- throw new Error('The game doesn\'t support validation');
9
+ throw new Error("The game doesn't support validation");
10
+ }
11
+ }
12
+ function validateLegacyMeta(metaPrivate, metaPublic, gameConfig) {
13
+ if (!gameConfig.hasMeta && (metaPrivate !== undefined || metaPublic !== undefined)) {
14
+ throw new Error('The game does not support meta data. metaPrivate and metaPublic are not allowed');
9
15
  }
10
16
  }
11
17
  const validateRouteValidatePlugin = (0, fastify_helper_1.registerPlugin)(async (fastify) => {
@@ -16,11 +22,11 @@ const validateRouteValidatePlugin = (0, fastify_helper_1.registerPlugin)(async (
16
22
  try {
17
23
  validateAccessibility(gameConfig);
18
24
  (0, play_route_validate_plugin_1.validateStakes)(body.stakes, gameConfig, stakesMap);
19
- (0, play_route_validate_plugin_1.validateMeta)(body.metaPrivate, body.metaPublic, gameConfig);
25
+ validateLegacyMeta(body.metaPrivate, body.metaPublic, gameConfig);
20
26
  done();
21
27
  }
22
28
  catch (error) {
23
- throw (0, fastify_helper_1.httpError)(`Advanced validation failed: ${error.message}`, 400);
29
+ throw (0, fastify_helper_1.httpError)(`Advanced validation failed: ${error.message}`, 400, errors_helper_1.EErrorCode.ValidationBody);
24
30
  }
25
31
  });
26
32
  });
@@ -1 +1 @@
1
- {"version":3,"file":"validate.route.validate.plugin.js","sourceRoot":"","sources":["../../../routes/validate/validate.route.validate.plugin.ts"],"names":[],"mappings":";;AAAA,+DAAwE;AACxE,iEAAwE;AAExE,mFAAiF;AAEjF,SAAS,qBAAqB,CAAC,UAAuB;IAClD,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAA;IAC3D,CAAC;AACL,CAAC;AAED,MAAM,2BAA2B,GAAG,IAAA,+BAAc,EAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACjE,MAAM,UAAU,GAAG,IAAA,6BAAa,GAAE,CAAA;IAElC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAA;IAEhG,OAAO,CAAC,OAAO,CAA4D,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;QAC/G,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAA;QAExB,IAAI,CAAC;YACD,qBAAqB,CAAC,UAAU,CAAC,CAAA;YACjC,IAAA,2CAAc,EAAC,IAAI,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,CAAA;YAClD,IAAA,yCAAY,EAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;YAE3D,IAAI,EAAE,CAAA;QACV,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,IAAA,0BAAS,EAAC,+BAA+B,KAAK,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,CAAA;QACxE,CAAC;IACL,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA;AAEF,kBAAe,2BAA2B,CAAA"}
1
+ {"version":3,"file":"validate.route.validate.plugin.js","sourceRoot":"","sources":["../../../routes/validate/validate.route.validate.plugin.ts"],"names":[],"mappings":";;AAAA,+DAAwE;AACxE,+DAAwD;AACxD,iEAAwE;AAExE,mFAAmE;AAEnE,SAAS,qBAAqB,CAAC,UAAuB;IAClD,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;IAC1D,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CAAC,WAA+B,EAAE,UAA8B,EAAE,UAAuB;IAChH,IAAI,CAAC,UAAU,CAAC,OAAO,IAAI,CAAC,WAAW,KAAK,SAAS,IAAI,UAAU,KAAK,SAAS,CAAC,EAAE,CAAC;QACjF,MAAM,IAAI,KAAK,CAAC,iFAAiF,CAAC,CAAA;IACtG,CAAC;AACL,CAAC;AAED,MAAM,2BAA2B,GAAG,IAAA,+BAAc,EAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACjE,MAAM,UAAU,GAAG,IAAA,6BAAa,GAAE,CAAA;IAElC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAA;IAEhG,OAAO,CAAC,OAAO,CAA4D,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;QAC/G,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAA;QAExB,IAAI,CAAC;YACD,qBAAqB,CAAC,UAAU,CAAC,CAAA;YACjC,IAAA,2CAAc,EAAC,IAAI,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,CAAA;YAClD,kBAAkB,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;YAEjE,IAAI,EAAE,CAAA;QACV,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,IAAA,0BAAS,EAAC,+BAA+B,KAAK,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,0BAAU,CAAC,cAAc,CAAC,CAAA;QACnG,CAAC;IACL,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA;AAEF,kBAAe,2BAA2B,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"healthcheck.route.d.ts","sourceRoot":"","sources":["../../routes-public/healthcheck.route.ts"],"names":[],"mappings":"AAQA,QAAA,MAAM,gBAAgB,gFAsBpB,CAAA;AAEF,eAAe,gBAAgB,CAAA"}
@@ -6,7 +6,7 @@ const fastify_helper_1 = require("../helpers/fastify.helper");
6
6
  const healthcheck_schema_1 = require("../schemas/healthcheck.schema");
7
7
  const shared_1 = require("../schemas/shared");
8
8
  const healthcheckRoute = (0, fastify_helper_1.registerRoute)(async (fastify) => {
9
- fastify.post('/healthcheck', {
9
+ fastify.get('/healthcheck', {
10
10
  schema: {
11
11
  response: {
12
12
  200: healthcheck_schema_1.HealthcheckReplySchema,
@@ -17,17 +17,11 @@ const healthcheckRoute = (0, fastify_helper_1.registerRoute)(async (fastify) =>
17
17
  headers: shared_1.HeadersSchema,
18
18
  },
19
19
  }, () => ({
20
- code: 200,
21
- status: true,
22
- service: (0, config_helper_1.getGameConfig)().name,
20
+ ok: true,
21
+ gameId: (0, config_helper_1.getGameConfig)().gameId,
23
22
  environment: (0, env_helper_1.variation)(shared_1.EEnvironment.development, shared_1.EEnvironment.staging, shared_1.EEnvironment.production),
24
23
  uptime: process.uptime(),
25
- message: 'OK',
26
- timestamp: new Date().getTime(),
27
- metrics: fastify.metrics,
28
- services: {
29
- sentry: !!fastify.Sentry,
30
- },
24
+ timestamp: Date.now(),
31
25
  }));
32
26
  });
33
27
  exports.default = healthcheckRoute;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"healthcheck.route.js","sourceRoot":"","sources":["../../routes-public/healthcheck.route.ts"],"names":[],"mappings":";;AAAA,4DAAwD;AACxD,sDAAiD;AACjD,8DAAyD;AACzD,sEAAsE;AACtE,8CAE0B;AAE1B,MAAM,gBAAgB,GAAG,IAAA,8BAAa,EAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACrD,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE;QACxB,MAAM,EAAE;YACJ,QAAQ,EAAE;gBACN,GAAG,EAAE,2CAAsB;gBAC3B,GAAG,EAAE,2BAAkB;gBACvB,GAAG,EAAE,0BAAiB;gBACtB,GAAG,EAAE,4BAAmB;aAC3B;YACD,OAAO,EAAE,sBAAa;SACzB;KACJ,EAAE,GAAG,EAAE,CAAC,CAAC;QACN,EAAE,EAAE,IAAa;QACjB,MAAM,EAAE,IAAA,6BAAa,GAAE,CAAC,MAAM;QAC9B,WAAW,EAAE,IAAA,sBAAS,EAClB,qBAAY,CAAC,WAAW,EACxB,qBAAY,CAAC,OAAO,EACpB,qBAAY,CAAC,UAAU,CAC1B;QACD,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;QACxB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACxB,CAAC,CAAC,CAAA;AACP,CAAC,CAAC,CAAA;AAEF,kBAAe,gBAAgB,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { Static, Type } from 'typebox';
2
+ export declare const ChecksumRequestSchema: Type.TObject<{}>;
3
+ export declare const ChecksumReplySchema: Type.TObject<{
4
+ files: Type.TArray<Type.TObject<{
5
+ path: Type.TString;
6
+ hash: Type.TString;
7
+ }>>;
8
+ }>;
9
+ export type TChecksumRequest = Static<typeof ChecksumRequestSchema>;
10
+ export type TChecksumReply = Static<typeof ChecksumReplySchema>;
11
+ //# sourceMappingURL=checksum.schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checksum.schema.d.ts","sourceRoot":"","sources":["../../schemas/checksum.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAItC,eAAO,MAAM,qBAAqB,kBAGhC,CAAA;AAEF,eAAO,MAAM,mBAAmB;;;;;EAe9B,CAAA;AAEF,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,qBAAqB,CAAC,CAAA;AACnE,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAA"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChecksumReplySchema = exports.ChecksumRequestSchema = void 0;
4
+ const typebox_1 = require("typebox");
5
+ const checksum_schema_examples_1 = require("./examples/checksum.schema.examples");
6
+ exports.ChecksumRequestSchema = typebox_1.Type.Object({}, {
7
+ $id: 'ChecksumRequest',
8
+ additionalProperties: false,
9
+ });
10
+ exports.ChecksumReplySchema = typebox_1.Type.Object({
11
+ files: typebox_1.Type.Array(typebox_1.Type.Object({
12
+ path: typebox_1.Type.String({
13
+ description: 'Path of the file, relative to the Game Server source root',
14
+ }),
15
+ hash: typebox_1.Type.String({
16
+ description: 'Hash of the file content. Algorithm and case (hex/base64) agreed with the RGS team',
17
+ }),
18
+ }, { additionalProperties: false }), {
19
+ description: 'List of files included in the integrity check',
20
+ }),
21
+ }, {
22
+ $id: 'ChecksumReply',
23
+ additionalProperties: false,
24
+ 'x-examples': checksum_schema_examples_1.checksumReplyExamples,
25
+ });
26
+ //# sourceMappingURL=checksum.schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checksum.schema.js","sourceRoot":"","sources":["../../schemas/checksum.schema.ts"],"names":[],"mappings":";;;AAAA,qCAAsC;AAEtC,kFAA2E;AAE9D,QAAA,qBAAqB,GAAG,cAAI,CAAC,MAAM,CAAC,EAAE,EAAE;IACjD,GAAG,EAAE,iBAAiB;IACtB,oBAAoB,EAAE,KAAK;CAC9B,CAAC,CAAA;AAEW,QAAA,mBAAmB,GAAG,cAAI,CAAC,MAAM,CAAC;IAC3C,KAAK,EAAE,cAAI,CAAC,KAAK,CAAC,cAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,EAAE,cAAI,CAAC,MAAM,CAAC;YACd,WAAW,EAAE,2DAA2D;SAC3E,CAAC;QACF,IAAI,EAAE,cAAI,CAAC,MAAM,CAAC;YACd,WAAW,EAAE,oFAAoF;SACpG,CAAC;KACL,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC,EAAE;QACjC,WAAW,EAAE,+CAA+C;KAC/D,CAAC;CACL,EAAE;IACC,GAAG,EAAE,eAAe;IACpB,oBAAoB,EAAE,KAAK;IAC3B,YAAY,EAAE,gDAAqB;CACtC,CAAC,CAAA"}