@getenginex/sdk-igaming 0.8.1 → 0.10.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.
@@ -1,6 +1,128 @@
1
- import { ok, fail } from '@getenginex/sdk/testing';
1
+ import { fail, ok } from '@getenginex/sdk/testing';
2
2
 
3
- // src/testing/bonus.ts
3
+ // src/testing/bets.ts
4
+ var SEED = [
5
+ {
6
+ id: "mock-bet-3",
7
+ status: "BET_STATUS_PENDING",
8
+ stake: 2e3,
9
+ potential_return: 5400,
10
+ total_odds: 2.7,
11
+ created_at: "2026-09-03T18:00:00Z",
12
+ selections: [
13
+ {
14
+ event_name: "Flamengo x Palmeiras",
15
+ market_name: "Resultado final",
16
+ selection_name: "Flamengo",
17
+ odds: 2.7,
18
+ result: "SELECTION_RESULT_PENDING"
19
+ }
20
+ ]
21
+ },
22
+ {
23
+ id: "mock-bet-2",
24
+ status: "BET_STATUS_WON",
25
+ stake: 1e3,
26
+ potential_return: 3150,
27
+ total_odds: 3.15,
28
+ created_at: "2026-09-02T20:00:00Z",
29
+ selections: [
30
+ {
31
+ event_name: "Corinthians x Santos",
32
+ market_name: "Ambas marcam",
33
+ selection_name: "Sim",
34
+ odds: 1.75,
35
+ result: "SELECTION_RESULT_WON"
36
+ },
37
+ {
38
+ event_name: "Gr\xEAmio x Inter",
39
+ market_name: "Total de gols",
40
+ selection_name: "Mais de 2.5",
41
+ odds: 1.8,
42
+ result: "SELECTION_RESULT_WON"
43
+ }
44
+ ]
45
+ },
46
+ {
47
+ id: "mock-bet-1",
48
+ status: "BET_STATUS_LOST",
49
+ stake: 500,
50
+ potential_return: 950,
51
+ total_odds: 1.9,
52
+ created_at: "2026-09-01T15:30:00Z",
53
+ selections: [
54
+ {
55
+ event_name: "S\xE3o Paulo x Vasco",
56
+ market_name: "Resultado final",
57
+ selection_name: "Vasco",
58
+ odds: 1.9,
59
+ result: "SELECTION_RESULT_LOST"
60
+ }
61
+ ]
62
+ }
63
+ ];
64
+ function pageOf(req, items) {
65
+ const q = req.url.searchParams;
66
+ const page = Math.max(1, Number.parseInt(q.get("page") ?? "", 10) || 1);
67
+ const raw = Number.parseInt(q.get("limit") ?? "", 10);
68
+ const limit = raw >= 1 && raw <= 100 ? raw : 20;
69
+ return {
70
+ items: items.slice((page - 1) * limit, page * limit),
71
+ meta: { page, per_page: limit, total_pages: Math.ceil(items.length / limit), total_items: items.length }
72
+ };
73
+ }
74
+ var EPOCH = "1970-01-01T00:00:00Z";
75
+ function createBetsRoutes() {
76
+ const bets = SEED.map((bet) => ({ ...bet }));
77
+ const replays = /* @__PURE__ */ new Map();
78
+ const find = (req) => bets.find((bet) => bet.id === req.params?.betId);
79
+ const offerOf = (bet) => bet.status === "BET_STATUS_PENDING" ? Math.floor(Number(bet.potential_return) * 80 / 100) : 0;
80
+ const summary = (bet) => {
81
+ const { selections, ...rest } = bet;
82
+ return rest;
83
+ };
84
+ return {
85
+ "GET /api/v1/bets": (req) => {
86
+ const { items, meta } = pageOf(req, bets);
87
+ return ok(items.map(summary), meta);
88
+ },
89
+ "GET /api/v1/bets/:betId": (req) => {
90
+ const bet = find(req);
91
+ return bet ? ok(bet) : fail(404, "BET_NOT_FOUND", "bet not found");
92
+ },
93
+ "GET /api/v1/bets/:betId/cashout": (req) => {
94
+ const bet = find(req);
95
+ if (!bet) return fail(404, "BET_NOT_FOUND", "bet not found");
96
+ const amount = offerOf(bet);
97
+ return ok({
98
+ bet_id: bet.id,
99
+ available: amount > 0,
100
+ cashout_amount: amount,
101
+ expires_at: amount > 0 ? new Date(Date.now() + 15e3).toISOString().replace(/\.\d{3}Z$/, "Z") : EPOCH
102
+ });
103
+ },
104
+ "POST /api/v1/bets/:betId/cashout": (req) => {
105
+ const key = req.headers.get("idempotency-key") ?? "";
106
+ if (key === "" || key !== key.trim())
107
+ return fail(400, "INVALID_ARGUMENT", "Idempotency-Key must be normalized and non-empty");
108
+ const replayKey = `${String(req.params?.betId)}:${key}`;
109
+ const replay = replays.get(replayKey);
110
+ if (replay)
111
+ return replay.status === 200 ? ok(replay.body) : fail(replay.status, "FAILED_PRECONDITION", "cashout not available");
112
+ const bet = find(req);
113
+ if (!bet) return fail(404, "BET_NOT_FOUND", "bet not found");
114
+ const amount = offerOf(bet);
115
+ if (amount === 0) {
116
+ replays.set(replayKey, { status: 422, body: null });
117
+ return fail(422, "FAILED_PRECONDITION", "cashout not available");
118
+ }
119
+ bet.status = "BET_STATUS_CASHED_OUT";
120
+ const body = { bet_id: bet.id, cashout_amount: amount, status: "cashed_out" };
121
+ replays.set(replayKey, { status: 200, body });
122
+ return ok(body);
123
+ }
124
+ };
125
+ }
4
126
  var uuid = (n) => `c0000000-0000-4000-8000-${String(n).padStart(12, "0")}`;
5
127
  var WINDOW = { starts_at: "2026-09-01T03:00:00Z", ends_at: "2027-01-01T03:00:00Z" };
6
128
  var brl = (minor) => ({ amount: String(minor), currency: "BRL" });
@@ -58,7 +180,9 @@ var WELCOME = offer(
58
180
  requirement_basis: "REQUIREMENT_BASIS_GRANTED_BALANCE",
59
181
  multiplier: { decimal: "30" },
60
182
  contribution_rates: [{ casino: { category_codes: ["slots"] }, rate: { basis_points: 1e4 } }],
61
- rounding: "ROUNDING_MODE_HALF_UP"
183
+ rounding: "ROUNDING_MODE_HALF_UP",
184
+ // "Maximum withdrawal": at most R$ 250 of the bonus becomes real money.
185
+ maximum_conversion: { amount: "25000", currency: "BRL" }
62
186
  }
63
187
  },
64
188
  stacking_policy: { version: 1, exclusive_in_group: { stacking_group_key: "welcome" } }
@@ -431,10 +555,49 @@ var WINNERS = [
431
555
  game_name: GAMES.find((g) => g.id === gameId)?.name,
432
556
  won_at: wonAt
433
557
  }));
558
+ var JACKPOT_CURRENCY = "BRL";
559
+ var SUPPORTED_CURRENCIES = /* @__PURE__ */ new Set(["BRL", "USD", "EUR", "CLP", "MXN", "ARS", "PEN", "COP"]);
560
+ var JACKPOTS = [
561
+ { id: `jackpot_${"a1".repeat(32)}`, name: "Mega Jackpot", amount_minor: "125000000", games: [0, 1, 2, 6] },
562
+ { id: `jackpot_${"b2".repeat(32)}`, name: "Jackpot Ao Vivo", amount_minor: "4875050", games: [3, 4, 5] }
563
+ ];
564
+ var JACKPOT_ID = /^jackpot_[0-9a-f]{64}$/;
565
+ var JACKPOT_CURSOR = /^[A-Za-z0-9_-]+$/;
566
+ function jackpotCurrency(req) {
567
+ const values = req.url.searchParams.getAll("currency");
568
+ if (values.length !== 1 || !SUPPORTED_CURRENCIES.has(values[0]))
569
+ return fail(400, "INVALID_ARGUMENT", "a supported currency is required");
570
+ return values[0];
571
+ }
572
+ function listJackpotGames(req) {
573
+ const id = req.params?.jackpotId ?? "";
574
+ if (!JACKPOT_ID.test(id)) return fail(400, "INVALID_ARGUMENT", "invalid jackpot ID");
575
+ const currency = jackpotCurrency(req);
576
+ if (currency instanceof Response) return currency;
577
+ const jackpot = JACKPOTS.find((j) => j.id === id);
578
+ if (currency !== JACKPOT_CURRENCY || !jackpot) return fail(404, "NOT_FOUND", "jackpot not found");
579
+ const q = req.url.searchParams;
580
+ const device = (q.get("device") ?? "").trim().toLowerCase();
581
+ const page = q.get("page") === null ? 1 : Number(q.get("page"));
582
+ const limit = q.get("limit") === null ? 24 : Number(q.get("limit"));
583
+ if (!["", "mobile", "desktop"].includes(device) || !Number.isInteger(page) || page < 1 || !Number.isInteger(limit) || limit < 1 || limit > 48)
584
+ return fail(400, "INVALID_ARGUMENT", "invalid jackpot games filters");
585
+ const cursor = q.get("cursor") ?? "";
586
+ if (page > 1 && cursor !== `page-${page}` || cursor !== "" && !JACKPOT_CURSOR.test(cursor))
587
+ return fail(400, "INVALID_ARGUMENT", "invalid jackpot games cursor");
588
+ const games = jackpot.games.map((i) => GAMES[i]).filter((g) => device !== "mobile" || g.is_live !== true);
589
+ const items = games.slice((page - 1) * limit, page * limit);
590
+ const next = page * limit < games.length ? `page-${page + 1}` : "";
591
+ return ok({
592
+ games: items,
593
+ mode: "verified",
594
+ pagination: { page, per_page: limit, has_next: next !== "", next_cursor: next }
595
+ });
596
+ }
434
597
  function json(body, status = 200) {
435
598
  return new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
436
599
  }
437
- function pageOf(req, items) {
600
+ function pageOf2(req, items) {
438
601
  const q = req.url.searchParams;
439
602
  const page = Math.max(1, Number.parseInt(q.get("page") ?? "", 10) || 1);
440
603
  const raw = Number.parseInt(q.get("limit") ?? "", 10);
@@ -461,11 +624,11 @@ function listGames(req) {
461
624
  (g) => (!category || g.category === category) && (!provider || g.provider === provider) && (!search || String(g.name).toLowerCase().includes(search)) && (ids.length === 0 || ids.includes(String(g.id)))
462
625
  );
463
626
  const sort = SORTS[q.get("sort") ?? ""];
464
- const { items, meta } = pageOf(req, sort ? [...games].sort(sort) : games);
627
+ const { items, meta } = pageOf2(req, sort ? [...games].sort(sort) : games);
465
628
  return json({
466
629
  success: true,
467
630
  data: items,
468
- availability: { status: "available", primary_provider_code: "pragmatic-play", missing: false },
631
+ availability: { status: "available", primary_provider_code: "pragmatic-play", missing: null },
469
632
  meta
470
633
  });
471
634
  }
@@ -499,6 +662,22 @@ function createCasinoRoutes() {
499
662
  }))
500
663
  ),
501
664
  "GET /api/v1/games/providers": () => ok(PROVIDERS.map(([id, name]) => ({ id, name, game_count: GAMES.filter((g) => g.provider === id).length }))),
665
+ "GET /api/v1/games/jackpots": (req) => {
666
+ const currency = jackpotCurrency(req);
667
+ if (currency instanceof Response) return currency;
668
+ if (currency !== JACKPOT_CURRENCY) return ok({ items: [], featured_id: "" });
669
+ return ok({
670
+ items: JACKPOTS.map(({ id, name, amount_minor }) => ({
671
+ id,
672
+ name,
673
+ currency: JACKPOT_CURRENCY,
674
+ amount_minor,
675
+ decimal_places: 2
676
+ })),
677
+ featured_id: JACKPOTS[0].id
678
+ });
679
+ },
680
+ "GET /api/v1/games/jackpots/:jackpotId/games": listJackpotGames,
502
681
  "GET /api/v1/games/:gameId": (req) => {
503
682
  const game = GAMES.find((g) => g.id === req.params?.gameId);
504
683
  return game ? ok(game) : fail(404, "GAME_NOT_FOUND", "game not found");
@@ -533,11 +712,11 @@ function createCasinoRoutes() {
533
712
  });
534
713
  },
535
714
  "GET /api/v1/games/sessions": (req) => {
536
- const { items, meta } = pageOf(req, sessions);
715
+ const { items, meta } = pageOf2(req, sessions);
537
716
  return ok(items, meta);
538
717
  },
539
718
  "GET /api/v1/games/history": (req) => {
540
- const { items, meta } = pageOf(req, HISTORY);
719
+ const { items, meta } = pageOf2(req, HISTORY);
541
720
  return ok(items, meta);
542
721
  },
543
722
  "GET /api/v1/games/biggest-winners": (req) => {
@@ -582,7 +761,7 @@ function createLoyaltyRoutes() {
582
761
  }
583
762
  };
584
763
  }
585
- var EPOCH = "1970-01-01T00:00:00Z";
764
+ var EPOCH2 = "1970-01-01T00:00:00Z";
586
765
  var MISSIONS = [
587
766
  [
588
767
  "Aposte R$ 100 hoje",
@@ -606,10 +785,10 @@ var MISSIONS = [
606
785
  "free_spins",
607
786
  10,
608
787
  "2026-09-01T00:00:00Z",
609
- EPOCH
788
+ EPOCH2
610
789
  ],
611
- ["Jogue Aviator", "event", "play_game", 5, "", ["mock-game-7"], "bonus", 500, EPOCH, EPOCH],
612
- ["Primeiro dep\xF3sito do m\xEAs", "permanent", "deposit", 5e3, "", null, "free_bet", 1e3, EPOCH, EPOCH]
790
+ ["Jogue Aviator", "event", "play_game", 5, "", ["mock-game-7"], "bonus", 500, EPOCH2, EPOCH2],
791
+ ["Primeiro dep\xF3sito do m\xEAs", "permanent", "deposit", 5e3, "", null, "free_bet", 1e3, EPOCH2, EPOCH2]
613
792
  ].map(([name, type, objective, target, category, games, rewardType, rewardValue, from, to], i) => ({
614
793
  id: `mock-mission-${i + 1}`,
615
794
  name,
@@ -753,7 +932,8 @@ function createIgamingRoutes() {
753
932
  ...createSportsbookRoutes(),
754
933
  ...createMissionsRoutes(),
755
934
  ...createLoyaltyRoutes(),
756
- ...createReferralsRoutes()
935
+ ...createReferralsRoutes(),
936
+ ...createBetsRoutes()
757
937
  };
758
938
  }
759
939
  function withIgamingRoutes(options = {}) {