@getenginex/sdk-igaming 0.9.0 → 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.
@@ -9,7 +9,7 @@ var methodOf = (igaming, namespace, method) => (input, options) => igaming[names
9
9
  options
10
10
  );
11
11
  var PUBLIC_READS = {
12
- casino: ["listGames", "listCategories", "listProviders", "getGame"],
12
+ casino: ["listGames", "listCategories", "listProviders", "getGame", "listJackpots", "listJackpotGames"],
13
13
  bonus: ["listPublicOffers"]
14
14
  };
15
15
  var USER_READS = {
@@ -17,7 +17,8 @@ var USER_READS = {
17
17
  bonus: ["listOffers", "getOffer", "listParticipations", "getParticipation", "getOverview", "listPositions"],
18
18
  missions: ["list", "listMine"],
19
19
  loyalty: ["get"],
20
- referrals: ["get", "listHistory"]
20
+ referrals: ["get", "listHistory"],
21
+ bets: ["list", "get", "getCashoutOffer"]
21
22
  };
22
23
  var userKeys = (...prefixes) => (scope) => prefixes.map(([namespace, method]) => scope.userPrefix(namespace, method));
23
24
  var none = () => [];
@@ -30,7 +31,8 @@ var WRITES = {
30
31
  redeemPromoCode: { invalidates: userKeys(["bonus"], ["wallet"]), idempotent: true, sensitive: true }
31
32
  },
32
33
  loyalty: { redeem: { invalidates: userKeys(["loyalty"], ["wallet"]), idempotent: true } },
33
- sportsbook: { createSession: { invalidates: none, sensitive: true } }
34
+ sportsbook: { createSession: { invalidates: none, sensitive: true } },
35
+ bets: { cashout: { invalidates: userKeys(["bets"], ["wallet"]), idempotent: true } }
34
36
  };
35
37
  function createIgamingQueries(igaming) {
36
38
  const scope = query.queryScope(igaming);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/query/index.ts"],"names":["queryScope"],"mappings":";;;;;AAyEA,IAAM,QAAA,GAAW,CAAC,OAAA,EAAiB,SAAA,EAAmB,MAAA,KAAmB,CAAC,KAAA,EAAgB,OAAA,KACtF,OAAA,CAAmD,SAAS,CAAA,CAAG,MAAM,CAAA,CAAa,I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;AACT","file":"index.cjs","sourcesContent":["/**\n * iGaming query and mutation factories, compatible with TanStack Query v5 (`useQuery`,\n * `useMutation`, `prefetchQuery`), without depending on it. Same key conventions as\n * `@getenginex/sdk/query`.\n * @module @getenginex/sdk-igaming/query\n */\n\nimport type { CallOptions } from '@getenginex/sdk'\nimport {\n queryScope,\n type IdempotentMutationsOf,\n type MutationsOf,\n type QueriesOf,\n type QueryScope,\n} from '@getenginex/sdk/query'\nimport type { IgamingClient } from '../client'\nimport type { BonusApi } from '../modules/bonus'\nimport type { CasinoApi } from '../modules/casino'\nimport type { LoyaltyApi } from '../modules/loyalty'\nimport type { MissionsApi } from '../modules/missions'\nimport type { ReferralsApi } from '../modules/referrals'\nimport type { SportsbookApi } from '../modules/sportsbook'\n\n/**\n * iGaming query factories, one per read method: `q.<namespace>.<method>(input)` returns\n * `{ queryKey, queryFn }`. Obtained with {@link createIgamingQueries}.\n * @category Queries\n */\nexport interface IgamingQueries {\n /** Catalog (public) and, with login, sessions, history and biggest winners. */\n readonly casino: QueriesOf<\n CasinoApi,\n 'listGames' | 'listCategories' | 'listProviders' | 'getGame' | 'listSessions' | 'getHistory' | 'getBiggestWinners'\n >\n /** Public offers (no login) and, with login, offers, participations, bonus overview and positions. */\n readonly bonus: QueriesOf<\n BonusApi,\n | 'listPublicOffers'\n | 'listOffers'\n | 'getOffer'\n | 'listParticipations'\n | 'getParticipation'\n | 'getOverview'\n | 'listPositions'\n >\n /** Operator missions and the player's own. */\n readonly missions: QueriesOf<MissionsApi, 'list' | 'listMine'>\n /** Points balance, tier and benefits. */\n readonly loyalty: QueriesOf<LoyaltyApi, 'get'>\n /** Referral code, program rules, totals and history. */\n readonly referrals: QueriesOf<ReferralsApi, 'get' | 'listHistory'>\n}\n\n/**\n * iGaming mutations, one per write method: `m.<namespace>.<method>()` returns\n * `{ mutationKey, mutationFn, invalidates }`. Obtained with {@link createIgamingMutations}.\n * @category Queries\n */\nexport interface IgamingMutations {\n /** Game launch (`launchGame`, with `gcTime: 0`: the game URL carries credentials). */\n readonly casino: MutationsOf<CasinoApi, 'launchGame'>\n /** Opt-in, redemption (idempotent: they accept `{ idempotencyKey }`) and promo code check. */\n readonly bonus: IdempotentMutationsOf<BonusApi, 'optIn' | 'claim' | 'redeemPromoCode'> &\n MutationsOf<BonusApi, 'resolvePromoCode'>\n /** Points redemption (idempotent: it accepts `{ idempotencyKey }`). */\n readonly loyalty: IdempotentMutationsOf<LoyaltyApi, 'redeem'>\n /** Sportsbook session (`gcTime: 0`: the URL carries the operator token). */\n readonly sportsbook: MutationsOf<SportsbookApi, 'createSession'>\n}\n\ntype Method = (input: unknown, options?: CallOptions) => Promise<unknown>\n\n// Calls `igaming[namespace][method]` at request time (not at creation), keeping `this`.\nconst methodOf = (igaming: object, namespace: string, method: string) => (input: unknown, options: CallOptions) =>\n ((igaming as Record<string, Record<string, Method>>)[namespace]![method] as Method).call(\n (igaming as Record<string, unknown>)[namespace],\n input,\n options,\n )\n\n// Reads without a session (the method sends no token): `public` key, no `staleTime`.\nconst PUBLIC_READS = {\n casino: ['listGames', 'listCategories', 'listProviders', 'getGame'],\n bonus: ['listPublicOffers'],\n} as const\n\n// Player reads: `user` key with the session's `userId`.\nconst USER_READS = {\n casino: ['listSessions', 'getHistory', 'getBiggestWinners'],\n bonus: ['listOffers', 'getOffer', 'listParticipations', 'getParticipation', 'getOverview', 'listPositions'],\n missions: ['list', 'listMine'],\n loyalty: ['get'],\n referrals: ['get', 'listHistory'],\n} as const\n\ntype Invalidation = (scope: QueryScope) => readonly (readonly unknown[])[]\nconst userKeys =\n (...prefixes: [namespace: string, method?: string][]): Invalidation =>\n (scope) =>\n prefixes.map(([namespace, method]) => scope.userPrefix(namespace, method))\nconst none: Invalidation = () => []\n\ninterface Write {\n /** What the write leaves stale. The core's prefixes (`wallet`) come from `scope.userPrefix`. */\n invalidates: Invalidation\n /** Sends `Idempotency-Key` (accepts `{ idempotencyKey }`). */\n idempotent?: boolean\n /** Entry or result with a credential: `gcTime: 0`. */\n sensitive?: boolean\n}\n\nconst WRITES: Record<string, Record<string, Write>> = {\n casino: { launchGame: { invalidates: userKeys(['casino', 'listSessions']), sensitive: true } },\n bonus: {\n resolvePromoCode: { invalidates: none, sensitive: true },\n optIn: { invalidates: userKeys(['bonus'], ['wallet']), idempotent: true },\n claim: { invalidates: userKeys(['bonus'], ['wallet']), idempotent: true },\n redeemPromoCode: { invalidates: userKeys(['bonus'], ['wallet']), idempotent: true, sensitive: true },\n },\n loyalty: { redeem: { invalidates: userKeys(['loyalty'], ['wallet']), idempotent: true } },\n sportsbook: { createSession: { invalidates: none, sensitive: true } },\n}\n\n/**\n * Creates the iGaming query factories: one per read method, with the same name and the same input\n * as the method (`q.casino.listGames({ page })`). Each call returns `{ queryKey, queryFn }`, compatible\n * with TanStack Query v5's `useQuery`/`prefetchQuery`/`fetchQuery`. It makes no request.\n *\n * - Reads without a session (`casino.listGames/listCategories/listProviders/getGame`,\n * `bonus.listPublicOffers`): key `['enginex', 'public', namespace, method, input?]`.\n * - Player reads (the others): key `['enginex', 'user', userId, namespace, method, input?]`,\n * with the session's `userId` when the factory is called; without a session, `'anonymous'` and the `queryFn`\n * rejects with `UNAUTHENTICATED` without a request (the same if the session switches user before the `fetch`).\n * - `queryFn` forwards the context's `signal`: canceling the query aborts the `fetch`.\n * - None carries `staleTime`.\n * @param igaming - The object returned by `createIgaming(enginex)` (the object itself, not a copy).\n * @example\n * import { useQuery } from '@tanstack/react-query'\n * import { createIgamingQueries } from '@getenginex/sdk-igaming/query'\n *\n * const q = createIgamingQueries(igaming)\n * const games = useQuery(q.casino.listGames({ category: 'slots' }))\n * @throws {EnginexError} `CONFIGURATION_ERROR` if `igaming` did not come from `createIgaming` (e.g. a\n * `{ ...igaming }` copy). Identify with `isEnginexError(error, 'CONFIGURATION_ERROR')`.\n * @category Queries\n */\nexport function createIgamingQueries(igaming: IgamingClient): IgamingQueries {\n const scope = queryScope(igaming)\n const out: Record<string, Record<string, (input?: unknown) => unknown>> = {}\n const add = (\n table: Record<string, readonly string[]>,\n build: (namespace: string, method: string, input: unknown) => unknown,\n ) => {\n for (const [namespace, methods] of Object.entries(table)) {\n const factories = (out[namespace] ??= {})\n for (const method of methods) factories[method] = (input) => build(namespace, method, input)\n }\n }\n add(PUBLIC_READS, (namespace, method, input) =>\n scope.publicQuery(namespace, method, methodOf(igaming, namespace, method), input),\n )\n add(USER_READS, (namespace, method, input) =>\n scope.userQuery(namespace, method, methodOf(igaming, namespace, method), input),\n )\n return out as unknown as IgamingQueries\n}\n\n/**\n * Creates the iGaming mutations: one per write method, with the same name as the method\n * (`m.loyalty.redeem()`). Each call returns `{ mutationKey, mutationFn, invalidates }`, compatible\n * with TanStack Query v5's `useMutation`; `invalidates(input, result)` lists the prefixes the write\n * leaves stale (with the session's `userId` at call time; call it only after success):\n *\n * - `bonus.optIn/claim/redeemPromoCode` → `bonus` and `wallet` (the core's balance);\n * - `loyalty.redeem` → `loyalty` and `wallet`;\n * - `casino.launchGame` → `casino.listSessions`; `bonus.resolvePromoCode` and\n * `sportsbook.createSession` → nothing.\n *\n * `mutationKey` is `['enginex', namespace, method]`, without the input. The ones that send `Idempotency-Key`\n * (`bonus.optIn/claim/redeemPromoCode`, `loyalty.redeem`) reuse the key only after an ambiguous\n * failure (network, timeout, 5xx, `KEY_IN_USE` or `VALIDATION_ERROR` after a 2xx) with the same input,\n * on this options object (see the core's `createMutations`), and accept `{ idempotencyKey }` on the factory. The\n * ones that carry credentials in the input or the result (promo code, game URL, sportsbook\n * session) have `gcTime: 0`.\n * @param igaming - The object returned by `createIgaming(enginex)` (the object itself, not a copy).\n * @example\n * import { useMutation } from '@tanstack/react-query'\n * import { createIgamingMutations } from '@getenginex/sdk-igaming/query'\n *\n * const m = createIgamingMutations(igaming)\n * const redeem = m.loyalty.redeem()\n * const result = await redeem.mutationFn({ points: 500, redemptionType: 'bonus' })\n * for (const queryKey of redeem.invalidates({ points: 500, redemptionType: 'bonus' }, result)) {\n * await queryClient.invalidateQueries({ queryKey })\n * }\n * @throws {EnginexError} `CONFIGURATION_ERROR` if `igaming` did not come from `createIgaming`.\n * @category Queries\n */\nexport function createIgamingMutations(igaming: IgamingClient): IgamingMutations {\n const scope = queryScope(igaming)\n const out: Record<string, Record<string, (options?: { idempotencyKey?: string }) => unknown>> = {}\n for (const [namespace, methods] of Object.entries(WRITES)) {\n const factories = (out[namespace] ??= {})\n for (const [method, write] of Object.entries(methods)) {\n factories[method] = (options) => {\n const scoped: { idempotent?: boolean; idempotencyKey?: string; gcTime?: number } = {}\n if (write.idempotent === true) {\n scoped.idempotent = true\n if (options?.idempotencyKey !== undefined) scoped.idempotencyKey = options.idempotencyKey\n }\n if (write.sensitive === true) scoped.gcTime = 0\n return scope.mutation(\n namespace,\n method,\n methodOf(igaming, namespace, method),\n () => write.invalidates(scope),\n scoped,\n )\n }\n }\n }\n return out as unknown as IgamingMutations\n}\n"]}
1
+ {"version":3,"sources":["../../src/query/index.ts"],"names":["queryScope"],"mappings":";;;;;AAsFA,IAAM,QAAA,GAAW,CAAC,OAAA,EAAiB,SAAA,EAAmB,MAAA,KAAmB,CAAC,KAAA,EAAgB,OAAA,KACtF,OAAA,CAAmD,SAAS,CAAA,CAAG,MAAM,CAAA,CAAa,IAAA;AAAA,EACjF,QAAoC,SAAS,CAAA;AAAA,EAC9C,KAAA;AAAA,EACA;AACF,CAAA;AAGF,IAAM,YAAA,GAAe;AAAA,EACnB,QAAQ,CAAC,WAAA,EAAa,kBAAkB,eAAA,EAAiB,SAAA,EAAW,gBAAgB,kBAAkB,CAAA;AAAA,EACtG,KAAA,EAAO,CAAC,kBAAkB;AAC5B,CAAA;AAGA,IAAM,UAAA,GAAa;AAAA,EACjB,MAAA,EAAQ,CAAC,cAAA,EAAgB,YAAA,EAAc,mBAAmB,CAAA;AAAA,EAC1D,OAAO,CAAC,YAAA,EAAc,YAAY,oBAAA,EAAsB,kBAAA,EAAoB,eAAe,eAAe,CAAA;AAAA,EAC1G,QAAA,EAAU,CAA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OAAA,EAA0C;AAC/E,EAAA,MAAM,KAAA,GAAQA,iBAAW,OAAO,CAAA;AAChC,EAAA,MAAM,MAA0F,EAAC;AACjG,EAAA,KAAA,MAAW,CAAC,SAAA,EAAW,OAAO,KAAK,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA,EAAG;AACzD,IAAA,MAAM,SAAA,GAAa,GAAA,CAAI,SAAS,CAAA,KAAM,EAAC;AACvC,IAAA,KAAA,MAAW,CAAC,MAAA,EAAQ,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,OAAO,CAAA,EAAG;AACrD,MAAA,SAAA,CAAU,MAAM,CAAA,GAAI,CAAC,OAAA,KAAY;AAC/B,QAAA,MAAM,SAA6E,EAAC;AACpF,QAAA,IAAI,KAAA,CAAM,eAAe,IAAA,EAAM;AAC7B,UAAA,MAAA,CAAO,UAAA,GAAa,IAAA;AACpB,UAAA,IAAI,OAAA,EAAS,cAAA,KAAmB,MAAA,EAAW,MAAA,CAAO,iBAAiB,OAAA,CAAQ,cAAA;AAAA,QAC7E;AACA,QAAA,IAAI,KAAA,CAAM,SAAA,KAAc,IAAA,EAAM,MAAA,CAAO,MAAA,GAAS,CAAA;AAC9C,QAAA,OAAO,KAAA,CAAM,QAAA;AAAA,UACX,SAAA;AAAA,UACA,MAAA;AAAA,UACA,QAAA,CAAS,OAAA,EAAS,SAAA,EAAW,MAAM,CAAA;AAAA,UACnC,MAAM,KAAA,CAAM,WAAA,CAAY,KAAK,CAAA;AAAA,UAC7B;AAAA,SACF;AAAA,MACF,CAAA;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,GAAA;AACT","file":"index.cjs","sourcesContent":["/**\n * iGaming query and mutation factories, compatible with TanStack Query v5 (`useQuery`,\n * `useMutation`, `prefetchQuery`), without depending on it. Same key conventions as\n * `@getenginex/sdk/query`.\n * @module @getenginex/sdk-igaming/query\n */\n\nimport type { CallOptions } from '@getenginex/sdk'\nimport {\n queryScope,\n type IdempotentMutationsOf,\n type MutationsOf,\n type QueriesOf,\n type QueryScope,\n} from '@getenginex/sdk/query'\nimport type { IgamingClient } from '../client'\nimport type { BetsApi } from '../modules/bets'\nimport type { BonusApi } from '../modules/bonus'\nimport type { CasinoApi } from '../modules/casino'\nimport type { LoyaltyApi } from '../modules/loyalty'\nimport type { MissionsApi } from '../modules/missions'\nimport type { ReferralsApi } from '../modules/referrals'\nimport type { SportsbookApi } from '../modules/sportsbook'\n\n/**\n * iGaming query factories, one per read method: `q.<namespace>.<method>(input)` returns\n * `{ queryKey, queryFn }`. Obtained with {@link createIgamingQueries}.\n * @category Queries\n */\nexport interface IgamingQueries {\n /** Catalog and lobby jackpots (public) and, with login, sessions, history and biggest winners. */\n readonly casino: QueriesOf<\n CasinoApi,\n | 'listGames'\n | 'listCategories'\n | 'listProviders'\n | 'getGame'\n | 'listJackpots'\n | 'listJackpotGames'\n | 'listSessions'\n | 'getHistory'\n | 'getBiggestWinners'\n >\n /** Public offers (no login) and, with login, offers, participations, bonus overview and positions. */\n readonly bonus: QueriesOf<\n BonusApi,\n | 'listPublicOffers'\n | 'listOffers'\n | 'getOffer'\n | 'listParticipations'\n | 'getParticipation'\n | 'getOverview'\n | 'listPositions'\n >\n /** Operator missions and the player's own. */\n readonly missions: QueriesOf<MissionsApi, 'list' | 'listMine'>\n /** Points balance, tier and benefits. */\n readonly loyalty: QueriesOf<LoyaltyApi, 'get'>\n /** Referral code, program rules, totals and history. */\n readonly referrals: QueriesOf<ReferralsApi, 'get' | 'listHistory'>\n /** The player's bets, a bet's details and its cash-out offer. */\n readonly bets: QueriesOf<BetsApi, 'list' | 'get' | 'getCashoutOffer'>\n}\n\n/**\n * iGaming mutations, one per write method: `m.<namespace>.<method>()` returns\n * `{ mutationKey, mutationFn, invalidates }`. Obtained with {@link createIgamingMutations}.\n * @category Queries\n */\nexport interface IgamingMutations {\n /** Game launch (`launchGame`, with `gcTime: 0`: the game URL carries credentials). */\n readonly casino: MutationsOf<CasinoApi, 'launchGame'>\n /** Opt-in, redemption (idempotent: they accept `{ idempotencyKey }`) and promo code check. */\n readonly bonus: IdempotentMutationsOf<BonusApi, 'optIn' | 'claim' | 'redeemPromoCode'> &\n MutationsOf<BonusApi, 'resolvePromoCode'>\n /** Points redemption (idempotent: it accepts `{ idempotencyKey }`). */\n readonly loyalty: IdempotentMutationsOf<LoyaltyApi, 'redeem'>\n /** Sportsbook session (`gcTime: 0`: the URL carries the operator token). */\n readonly sportsbook: MutationsOf<SportsbookApi, 'createSession'>\n /** Bet cash-out (idempotent: it accepts `{ idempotencyKey }`). */\n readonly bets: IdempotentMutationsOf<BetsApi, 'cashout'>\n}\n\ntype Method = (input: unknown, options?: CallOptions) => Promise<unknown>\n\n// Calls `igaming[namespace][method]` at request time (not at creation), keeping `this`.\nconst methodOf = (igaming: object, namespace: string, method: string) => (input: unknown, options: CallOptions) =>\n ((igaming as Record<string, Record<string, Method>>)[namespace]![method] as Method).call(\n (igaming as Record<string, unknown>)[namespace],\n input,\n options,\n )\n\n// Reads without a session (the method sends no token): `public` key, no `staleTime`.\nconst PUBLIC_READS = {\n casino: ['listGames', 'listCategories', 'listProviders', 'getGame', 'listJackpots', 'listJackpotGames'],\n bonus: ['listPublicOffers'],\n} as const\n\n// Player reads: `user` key with the session's `userId`.\nconst USER_READS = {\n casino: ['listSessions', 'getHistory', 'getBiggestWinners'],\n bonus: ['listOffers', 'getOffer', 'listParticipations', 'getParticipation', 'getOverview', 'listPositions'],\n missions: ['list', 'listMine'],\n loyalty: ['get'],\n referrals: ['get', 'listHistory'],\n bets: ['list', 'get', 'getCashoutOffer'],\n} as const\n\ntype Invalidation = (scope: QueryScope) => readonly (readonly unknown[])[]\nconst userKeys =\n (...prefixes: [namespace: string, method?: string][]): Invalidation =>\n (scope) =>\n prefixes.map(([namespace, method]) => scope.userPrefix(namespace, method))\nconst none: Invalidation = () => []\n\ninterface Write {\n /** What the write leaves stale. The core's prefixes (`wallet`) come from `scope.userPrefix`. */\n invalidates: Invalidation\n /** Sends `Idempotency-Key` (accepts `{ idempotencyKey }`). */\n idempotent?: boolean\n /** Entry or result with a credential: `gcTime: 0`. */\n sensitive?: boolean\n}\n\nconst WRITES: Record<string, Record<string, Write>> = {\n casino: { launchGame: { invalidates: userKeys(['casino', 'listSessions']), sensitive: true } },\n bonus: {\n resolvePromoCode: { invalidates: none, sensitive: true },\n optIn: { invalidates: userKeys(['bonus'], ['wallet']), idempotent: true },\n claim: { invalidates: userKeys(['bonus'], ['wallet']), idempotent: true },\n redeemPromoCode: { invalidates: userKeys(['bonus'], ['wallet']), idempotent: true, sensitive: true },\n },\n loyalty: { redeem: { invalidates: userKeys(['loyalty'], ['wallet']), idempotent: true } },\n sportsbook: { createSession: { invalidates: none, sensitive: true } },\n bets: { cashout: { invalidates: userKeys(['bets'], ['wallet']), idempotent: true } },\n}\n\n/**\n * Creates the iGaming query factories: one per read method, with the same name and the same input\n * as the method (`q.casino.listGames({ page })`). Each call returns `{ queryKey, queryFn }`, compatible\n * with TanStack Query v5's `useQuery`/`prefetchQuery`/`fetchQuery`. It makes no request.\n *\n * - Reads without a session (`casino.listGames/listCategories/listProviders/getGame/listJackpots/listJackpotGames`,\n * `bonus.listPublicOffers`): key `['enginex', 'public', namespace, method, input?]`.\n * - Player reads (the others): key `['enginex', 'user', userId, namespace, method, input?]`,\n * with the session's `userId` when the factory is called; without a session, `'anonymous'` and the `queryFn`\n * rejects with `UNAUTHENTICATED` without a request (the same if the session switches user before the `fetch`).\n * - `queryFn` forwards the context's `signal`: canceling the query aborts the `fetch`.\n * - None carries `staleTime`.\n * @param igaming - The object returned by `createIgaming(enginex)` (the object itself, not a copy).\n * @example\n * import { useQuery } from '@tanstack/react-query'\n * import { createIgamingQueries } from '@getenginex/sdk-igaming/query'\n *\n * const q = createIgamingQueries(igaming)\n * const games = useQuery(q.casino.listGames({ category: 'slots' }))\n * @throws {EnginexError} `CONFIGURATION_ERROR` if `igaming` did not come from `createIgaming` (e.g. a\n * `{ ...igaming }` copy). Identify with `isEnginexError(error, 'CONFIGURATION_ERROR')`.\n * @category Queries\n */\nexport function createIgamingQueries(igaming: IgamingClient): IgamingQueries {\n const scope = queryScope(igaming)\n const out: Record<string, Record<string, (input?: unknown) => unknown>> = {}\n const add = (\n table: Record<string, readonly string[]>,\n build: (namespace: string, method: string, input: unknown) => unknown,\n ) => {\n for (const [namespace, methods] of Object.entries(table)) {\n const factories = (out[namespace] ??= {})\n for (const method of methods) factories[method] = (input) => build(namespace, method, input)\n }\n }\n add(PUBLIC_READS, (namespace, method, input) =>\n scope.publicQuery(namespace, method, methodOf(igaming, namespace, method), input),\n )\n add(USER_READS, (namespace, method, input) =>\n scope.userQuery(namespace, method, methodOf(igaming, namespace, method), input),\n )\n return out as unknown as IgamingQueries\n}\n\n/**\n * Creates the iGaming mutations: one per write method, with the same name as the method\n * (`m.loyalty.redeem()`). Each call returns `{ mutationKey, mutationFn, invalidates }`, compatible\n * with TanStack Query v5's `useMutation`; `invalidates(input, result)` lists the prefixes the write\n * leaves stale (with the session's `userId` at call time; call it only after success):\n *\n * - `bonus.optIn/claim/redeemPromoCode` → `bonus` and `wallet` (the core's balance);\n * - `loyalty.redeem` → `loyalty` and `wallet`;\n * - `bets.cashout` → `bets` and `wallet`;\n * - `casino.launchGame` → `casino.listSessions`; `bonus.resolvePromoCode` and\n * `sportsbook.createSession` → nothing.\n *\n * `mutationKey` is `['enginex', namespace, method]`, without the input. The ones that send `Idempotency-Key`\n * (`bonus.optIn/claim/redeemPromoCode`, `loyalty.redeem`, `bets.cashout`) reuse the key only after an ambiguous\n * failure (network, timeout, 5xx, `KEY_IN_USE` or `VALIDATION_ERROR` after a 2xx) with the same input,\n * on this options object (see the core's `createMutations`), and accept `{ idempotencyKey }` on the factory. The\n * ones that carry credentials in the input or the result (promo code, game URL, sportsbook\n * session) have `gcTime: 0`.\n * @param igaming - The object returned by `createIgaming(enginex)` (the object itself, not a copy).\n * @example\n * import { useMutation } from '@tanstack/react-query'\n * import { createIgamingMutations } from '@getenginex/sdk-igaming/query'\n *\n * const m = createIgamingMutations(igaming)\n * const redeem = m.loyalty.redeem()\n * const result = await redeem.mutationFn({ points: 500, redemptionType: 'bonus' })\n * for (const queryKey of redeem.invalidates({ points: 500, redemptionType: 'bonus' }, result)) {\n * await queryClient.invalidateQueries({ queryKey })\n * }\n * @throws {EnginexError} `CONFIGURATION_ERROR` if `igaming` did not come from `createIgaming`.\n * @category Queries\n */\nexport function createIgamingMutations(igaming: IgamingClient): IgamingMutations {\n const scope = queryScope(igaming)\n const out: Record<string, Record<string, (options?: { idempotencyKey?: string }) => unknown>> = {}\n for (const [namespace, methods] of Object.entries(WRITES)) {\n const factories = (out[namespace] ??= {})\n for (const [method, write] of Object.entries(methods)) {\n factories[method] = (options) => {\n const scoped: { idempotent?: boolean; idempotencyKey?: string; gcTime?: number } = {}\n if (write.idempotent === true) {\n scoped.idempotent = true\n if (options?.idempotencyKey !== undefined) scoped.idempotencyKey = options.idempotencyKey\n }\n if (write.sensitive === true) scoped.gcTime = 0\n return scope.mutation(\n namespace,\n method,\n methodOf(igaming, namespace, method),\n () => write.invalidates(scope),\n scoped,\n )\n }\n }\n }\n return out as unknown as IgamingMutations\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { MutationsOf, IdempotentMutationsOf, QueriesOf } from '@getenginex/sdk/query';
2
- import { CasinoApi, BonusApi, LoyaltyApi, SportsbookApi, MissionsApi, ReferralsApi, IgamingClient } from '../index.cjs';
2
+ import { CasinoApi, BonusApi, LoyaltyApi, SportsbookApi, BetsApi, MissionsApi, ReferralsApi, IgamingClient } from '../index.cjs';
3
3
  import '@getenginex/sdk';
4
4
 
5
5
  /**
@@ -15,8 +15,8 @@ import '@getenginex/sdk';
15
15
  * @category Queries
16
16
  */
17
17
  interface IgamingQueries {
18
- /** Catalog (public) and, with login, sessions, history and biggest winners. */
19
- readonly casino: QueriesOf<CasinoApi, 'listGames' | 'listCategories' | 'listProviders' | 'getGame' | 'listSessions' | 'getHistory' | 'getBiggestWinners'>;
18
+ /** Catalog and lobby jackpots (public) and, with login, sessions, history and biggest winners. */
19
+ readonly casino: QueriesOf<CasinoApi, 'listGames' | 'listCategories' | 'listProviders' | 'getGame' | 'listJackpots' | 'listJackpotGames' | 'listSessions' | 'getHistory' | 'getBiggestWinners'>;
20
20
  /** Public offers (no login) and, with login, offers, participations, bonus overview and positions. */
21
21
  readonly bonus: QueriesOf<BonusApi, 'listPublicOffers' | 'listOffers' | 'getOffer' | 'listParticipations' | 'getParticipation' | 'getOverview' | 'listPositions'>;
22
22
  /** Operator missions and the player's own. */
@@ -25,6 +25,8 @@ interface IgamingQueries {
25
25
  readonly loyalty: QueriesOf<LoyaltyApi, 'get'>;
26
26
  /** Referral code, program rules, totals and history. */
27
27
  readonly referrals: QueriesOf<ReferralsApi, 'get' | 'listHistory'>;
28
+ /** The player's bets, a bet's details and its cash-out offer. */
29
+ readonly bets: QueriesOf<BetsApi, 'list' | 'get' | 'getCashoutOffer'>;
28
30
  }
29
31
  /**
30
32
  * iGaming mutations, one per write method: `m.<namespace>.<method>()` returns
@@ -40,13 +42,15 @@ interface IgamingMutations {
40
42
  readonly loyalty: IdempotentMutationsOf<LoyaltyApi, 'redeem'>;
41
43
  /** Sportsbook session (`gcTime: 0`: the URL carries the operator token). */
42
44
  readonly sportsbook: MutationsOf<SportsbookApi, 'createSession'>;
45
+ /** Bet cash-out (idempotent: it accepts `{ idempotencyKey }`). */
46
+ readonly bets: IdempotentMutationsOf<BetsApi, 'cashout'>;
43
47
  }
44
48
  /**
45
49
  * Creates the iGaming query factories: one per read method, with the same name and the same input
46
50
  * as the method (`q.casino.listGames({ page })`). Each call returns `{ queryKey, queryFn }`, compatible
47
51
  * with TanStack Query v5's `useQuery`/`prefetchQuery`/`fetchQuery`. It makes no request.
48
52
  *
49
- * - Reads without a session (`casino.listGames/listCategories/listProviders/getGame`,
53
+ * - Reads without a session (`casino.listGames/listCategories/listProviders/getGame/listJackpots/listJackpotGames`,
50
54
  * `bonus.listPublicOffers`): key `['enginex', 'public', namespace, method, input?]`.
51
55
  * - Player reads (the others): key `['enginex', 'user', userId, namespace, method, input?]`,
52
56
  * with the session's `userId` when the factory is called; without a session, `'anonymous'` and the `queryFn`
@@ -73,11 +77,12 @@ declare function createIgamingQueries(igaming: IgamingClient): IgamingQueries;
73
77
  *
74
78
  * - `bonus.optIn/claim/redeemPromoCode` → `bonus` and `wallet` (the core's balance);
75
79
  * - `loyalty.redeem` → `loyalty` and `wallet`;
80
+ * - `bets.cashout` → `bets` and `wallet`;
76
81
  * - `casino.launchGame` → `casino.listSessions`; `bonus.resolvePromoCode` and
77
82
  * `sportsbook.createSession` → nothing.
78
83
  *
79
84
  * `mutationKey` is `['enginex', namespace, method]`, without the input. The ones that send `Idempotency-Key`
80
- * (`bonus.optIn/claim/redeemPromoCode`, `loyalty.redeem`) reuse the key only after an ambiguous
85
+ * (`bonus.optIn/claim/redeemPromoCode`, `loyalty.redeem`, `bets.cashout`) reuse the key only after an ambiguous
81
86
  * failure (network, timeout, 5xx, `KEY_IN_USE` or `VALIDATION_ERROR` after a 2xx) with the same input,
82
87
  * on this options object (see the core's `createMutations`), and accept `{ idempotencyKey }` on the factory. The
83
88
  * ones that carry credentials in the input or the result (promo code, game URL, sportsbook
@@ -1,5 +1,5 @@
1
1
  import { MutationsOf, IdempotentMutationsOf, QueriesOf } from '@getenginex/sdk/query';
2
- import { CasinoApi, BonusApi, LoyaltyApi, SportsbookApi, MissionsApi, ReferralsApi, IgamingClient } from '../index.js';
2
+ import { CasinoApi, BonusApi, LoyaltyApi, SportsbookApi, BetsApi, MissionsApi, ReferralsApi, IgamingClient } from '../index.js';
3
3
  import '@getenginex/sdk';
4
4
 
5
5
  /**
@@ -15,8 +15,8 @@ import '@getenginex/sdk';
15
15
  * @category Queries
16
16
  */
17
17
  interface IgamingQueries {
18
- /** Catalog (public) and, with login, sessions, history and biggest winners. */
19
- readonly casino: QueriesOf<CasinoApi, 'listGames' | 'listCategories' | 'listProviders' | 'getGame' | 'listSessions' | 'getHistory' | 'getBiggestWinners'>;
18
+ /** Catalog and lobby jackpots (public) and, with login, sessions, history and biggest winners. */
19
+ readonly casino: QueriesOf<CasinoApi, 'listGames' | 'listCategories' | 'listProviders' | 'getGame' | 'listJackpots' | 'listJackpotGames' | 'listSessions' | 'getHistory' | 'getBiggestWinners'>;
20
20
  /** Public offers (no login) and, with login, offers, participations, bonus overview and positions. */
21
21
  readonly bonus: QueriesOf<BonusApi, 'listPublicOffers' | 'listOffers' | 'getOffer' | 'listParticipations' | 'getParticipation' | 'getOverview' | 'listPositions'>;
22
22
  /** Operator missions and the player's own. */
@@ -25,6 +25,8 @@ interface IgamingQueries {
25
25
  readonly loyalty: QueriesOf<LoyaltyApi, 'get'>;
26
26
  /** Referral code, program rules, totals and history. */
27
27
  readonly referrals: QueriesOf<ReferralsApi, 'get' | 'listHistory'>;
28
+ /** The player's bets, a bet's details and its cash-out offer. */
29
+ readonly bets: QueriesOf<BetsApi, 'list' | 'get' | 'getCashoutOffer'>;
28
30
  }
29
31
  /**
30
32
  * iGaming mutations, one per write method: `m.<namespace>.<method>()` returns
@@ -40,13 +42,15 @@ interface IgamingMutations {
40
42
  readonly loyalty: IdempotentMutationsOf<LoyaltyApi, 'redeem'>;
41
43
  /** Sportsbook session (`gcTime: 0`: the URL carries the operator token). */
42
44
  readonly sportsbook: MutationsOf<SportsbookApi, 'createSession'>;
45
+ /** Bet cash-out (idempotent: it accepts `{ idempotencyKey }`). */
46
+ readonly bets: IdempotentMutationsOf<BetsApi, 'cashout'>;
43
47
  }
44
48
  /**
45
49
  * Creates the iGaming query factories: one per read method, with the same name and the same input
46
50
  * as the method (`q.casino.listGames({ page })`). Each call returns `{ queryKey, queryFn }`, compatible
47
51
  * with TanStack Query v5's `useQuery`/`prefetchQuery`/`fetchQuery`. It makes no request.
48
52
  *
49
- * - Reads without a session (`casino.listGames/listCategories/listProviders/getGame`,
53
+ * - Reads without a session (`casino.listGames/listCategories/listProviders/getGame/listJackpots/listJackpotGames`,
50
54
  * `bonus.listPublicOffers`): key `['enginex', 'public', namespace, method, input?]`.
51
55
  * - Player reads (the others): key `['enginex', 'user', userId, namespace, method, input?]`,
52
56
  * with the session's `userId` when the factory is called; without a session, `'anonymous'` and the `queryFn`
@@ -73,11 +77,12 @@ declare function createIgamingQueries(igaming: IgamingClient): IgamingQueries;
73
77
  *
74
78
  * - `bonus.optIn/claim/redeemPromoCode` → `bonus` and `wallet` (the core's balance);
75
79
  * - `loyalty.redeem` → `loyalty` and `wallet`;
80
+ * - `bets.cashout` → `bets` and `wallet`;
76
81
  * - `casino.launchGame` → `casino.listSessions`; `bonus.resolvePromoCode` and
77
82
  * `sportsbook.createSession` → nothing.
78
83
  *
79
84
  * `mutationKey` is `['enginex', namespace, method]`, without the input. The ones that send `Idempotency-Key`
80
- * (`bonus.optIn/claim/redeemPromoCode`, `loyalty.redeem`) reuse the key only after an ambiguous
85
+ * (`bonus.optIn/claim/redeemPromoCode`, `loyalty.redeem`, `bets.cashout`) reuse the key only after an ambiguous
81
86
  * failure (network, timeout, 5xx, `KEY_IN_USE` or `VALIDATION_ERROR` after a 2xx) with the same input,
82
87
  * on this options object (see the core's `createMutations`), and accept `{ idempotencyKey }` on the factory. The
83
88
  * ones that carry credentials in the input or the result (promo code, game URL, sportsbook
@@ -7,7 +7,7 @@ var methodOf = (igaming, namespace, method) => (input, options) => igaming[names
7
7
  options
8
8
  );
9
9
  var PUBLIC_READS = {
10
- casino: ["listGames", "listCategories", "listProviders", "getGame"],
10
+ casino: ["listGames", "listCategories", "listProviders", "getGame", "listJackpots", "listJackpotGames"],
11
11
  bonus: ["listPublicOffers"]
12
12
  };
13
13
  var USER_READS = {
@@ -15,7 +15,8 @@ var USER_READS = {
15
15
  bonus: ["listOffers", "getOffer", "listParticipations", "getParticipation", "getOverview", "listPositions"],
16
16
  missions: ["list", "listMine"],
17
17
  loyalty: ["get"],
18
- referrals: ["get", "listHistory"]
18
+ referrals: ["get", "listHistory"],
19
+ bets: ["list", "get", "getCashoutOffer"]
19
20
  };
20
21
  var userKeys = (...prefixes) => (scope) => prefixes.map(([namespace, method]) => scope.userPrefix(namespace, method));
21
22
  var none = () => [];
@@ -28,7 +29,8 @@ var WRITES = {
28
29
  redeemPromoCode: { invalidates: userKeys(["bonus"], ["wallet"]), idempotent: true, sensitive: true }
29
30
  },
30
31
  loyalty: { redeem: { invalidates: userKeys(["loyalty"], ["wallet"]), idempotent: true } },
31
- sportsbook: { createSession: { invalidates: none, sensitive: true } }
32
+ sportsbook: { createSession: { invalidates: none, sensitive: true } },
33
+ bets: { cashout: { invalidates: userKeys(["bets"], ["wallet"]), idempotent: true } }
32
34
  };
33
35
  function createIgamingQueries(igaming) {
34
36
  const scope = queryScope(igaming);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/query/index.ts"],"names":[],"mappings":";;;AAyEA,IAAM,QAAA,GAAW,CAAC,OAAA,EAAiB,SAAA,EAAmB,MAAA,KAAmB,CAAC,KAAA,EAAgB,OAAA,KACtF,OAAA,CAAmD,SAAS,CAAA,CAAG,MAAM,CAAA,CAAa,IAAA;AAAA,EACjF,QAAoC,SAAS,CAAA;AAAA,EAC9C,KAAA;AAAA,EACA;AACF,CAAA;AAGF,IAAM,YAAA,GAAe;AAAA,EACnB,MAAA,EAAQ,CAAC,WAAA,EAAa,gBAAA,EAAkB,iBAAiB,SAAS,CAAA;AAAA,EAClE,KAAA,EAAO,CAAC,kBAAkB;AAC5B,CAAA;AAGA,IAAM,UAAA,GAAa;AAAA,EACjB,MAAA,EAAQ,CAAC,cAAA,EAAgB,YAAA,EAAc,mBAAmB,CAAA;AAAA,EAC1D,OAAO,CAAC,YAAA,EAAc,YAAY,oBAAA,EAAsB,kBAAA,EAAoB,eAAe,eAAe,CAAA;AAAA,EAC1G,QAAA,EAAU,CAAC,MAAA,EAAQ,UAAU,CAAA;AAAA,EAC7B,OAAA,EAAS,CAAC,KAAK,CAAA;AAAA,EACf,SAAA,EAAW,CAAC,KAAA,EAAO,aAAa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AAQ,OAAO,CAAA,EAAG;AACrD,MAAA,SAAA,CAAU,MAAM,CAAA,GAAI,CAAC,OAAA,KAAY;AAC/B,QAAA,MAAM,SAA6E,EAAC;AACpF,QAAA,IAAI,KAAA,CAAM,eAAe,IAAA,EAAM;AAC7B,UAAA,MAAA,CAAO,UAAA,GAAa,IAAA;AACpB,UAAA,IAAI,OAAA,EAAS,cAAA,KAAmB,MAAA,EAAW,MAAA,CAAO,iBAAiB,OAAA,CAAQ,cAAA;AAAA,QAC7E;AACA,QAAA,IAAI,KAAA,CAAM,SAAA,KAAc,IAAA,EAAM,MAAA,CAAO,MAAA,GAAS,CAAA;AAC9C,QAAA,OAAO,KAAA,CAAM,QAAA;AAAA,UACX,SAAA;AAAA,UACA,MAAA;AAAA,UACA,QAAA,CAAS,OAAA,EAAS,SAAA,EAAW,MAAM,CAAA;AAAA,UACnC,MAAM,KAAA,CAAM,WAAA,CAAY,KAAK,CAAA;AAAA,UAC7B;AAAA,SACF;AAAA,MACF,CAAA;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,GAAA;AACT","file":"index.js","sourcesContent":["/**\n * iGaming query and mutation factories, compatible with TanStack Query v5 (`useQuery`,\n * `useMutation`, `prefetchQuery`), without depending on it. Same key conventions as\n * `@getenginex/sdk/query`.\n * @module @getenginex/sdk-igaming/query\n */\n\nimport type { CallOptions } from '@getenginex/sdk'\nimport {\n queryScope,\n type IdempotentMutationsOf,\n type MutationsOf,\n type QueriesOf,\n type QueryScope,\n} from '@getenginex/sdk/query'\nimport type { IgamingClient } from '../client'\nimport type { BonusApi } from '../modules/bonus'\nimport type { CasinoApi } from '../modules/casino'\nimport type { LoyaltyApi } from '../modules/loyalty'\nimport type { MissionsApi } from '../modules/missions'\nimport type { ReferralsApi } from '../modules/referrals'\nimport type { SportsbookApi } from '../modules/sportsbook'\n\n/**\n * iGaming query factories, one per read method: `q.<namespace>.<method>(input)` returns\n * `{ queryKey, queryFn }`. Obtained with {@link createIgamingQueries}.\n * @category Queries\n */\nexport interface IgamingQueries {\n /** Catalog (public) and, with login, sessions, history and biggest winners. */\n readonly casino: QueriesOf<\n CasinoApi,\n 'listGames' | 'listCategories' | 'listProviders' | 'getGame' | 'listSessions' | 'getHistory' | 'getBiggestWinners'\n >\n /** Public offers (no login) and, with login, offers, participations, bonus overview and positions. */\n readonly bonus: QueriesOf<\n BonusApi,\n | 'listPublicOffers'\n | 'listOffers'\n | 'getOffer'\n | 'listParticipations'\n | 'getParticipation'\n | 'getOverview'\n | 'listPositions'\n >\n /** Operator missions and the player's own. */\n readonly missions: QueriesOf<MissionsApi, 'list' | 'listMine'>\n /** Points balance, tier and benefits. */\n readonly loyalty: QueriesOf<LoyaltyApi, 'get'>\n /** Referral code, program rules, totals and history. */\n readonly referrals: QueriesOf<ReferralsApi, 'get' | 'listHistory'>\n}\n\n/**\n * iGaming mutations, one per write method: `m.<namespace>.<method>()` returns\n * `{ mutationKey, mutationFn, invalidates }`. Obtained with {@link createIgamingMutations}.\n * @category Queries\n */\nexport interface IgamingMutations {\n /** Game launch (`launchGame`, with `gcTime: 0`: the game URL carries credentials). */\n readonly casino: MutationsOf<CasinoApi, 'launchGame'>\n /** Opt-in, redemption (idempotent: they accept `{ idempotencyKey }`) and promo code check. */\n readonly bonus: IdempotentMutationsOf<BonusApi, 'optIn' | 'claim' | 'redeemPromoCode'> &\n MutationsOf<BonusApi, 'resolvePromoCode'>\n /** Points redemption (idempotent: it accepts `{ idempotencyKey }`). */\n readonly loyalty: IdempotentMutationsOf<LoyaltyApi, 'redeem'>\n /** Sportsbook session (`gcTime: 0`: the URL carries the operator token). */\n readonly sportsbook: MutationsOf<SportsbookApi, 'createSession'>\n}\n\ntype Method = (input: unknown, options?: CallOptions) => Promise<unknown>\n\n// Calls `igaming[namespace][method]` at request time (not at creation), keeping `this`.\nconst methodOf = (igaming: object, namespace: string, method: string) => (input: unknown, options: CallOptions) =>\n ((igaming as Record<string, Record<string, Method>>)[namespace]![method] as Method).call(\n (igaming as Record<string, unknown>)[namespace],\n input,\n options,\n )\n\n// Reads without a session (the method sends no token): `public` key, no `staleTime`.\nconst PUBLIC_READS = {\n casino: ['listGames', 'listCategories', 'listProviders', 'getGame'],\n bonus: ['listPublicOffers'],\n} as const\n\n// Player reads: `user` key with the session's `userId`.\nconst USER_READS = {\n casino: ['listSessions', 'getHistory', 'getBiggestWinners'],\n bonus: ['listOffers', 'getOffer', 'listParticipations', 'getParticipation', 'getOverview', 'listPositions'],\n missions: ['list', 'listMine'],\n loyalty: ['get'],\n referrals: ['get', 'listHistory'],\n} as const\n\ntype Invalidation = (scope: QueryScope) => readonly (readonly unknown[])[]\nconst userKeys =\n (...prefixes: [namespace: string, method?: string][]): Invalidation =>\n (scope) =>\n prefixes.map(([namespace, method]) => scope.userPrefix(namespace, method))\nconst none: Invalidation = () => []\n\ninterface Write {\n /** What the write leaves stale. The core's prefixes (`wallet`) come from `scope.userPrefix`. */\n invalidates: Invalidation\n /** Sends `Idempotency-Key` (accepts `{ idempotencyKey }`). */\n idempotent?: boolean\n /** Entry or result with a credential: `gcTime: 0`. */\n sensitive?: boolean\n}\n\nconst WRITES: Record<string, Record<string, Write>> = {\n casino: { launchGame: { invalidates: userKeys(['casino', 'listSessions']), sensitive: true } },\n bonus: {\n resolvePromoCode: { invalidates: none, sensitive: true },\n optIn: { invalidates: userKeys(['bonus'], ['wallet']), idempotent: true },\n claim: { invalidates: userKeys(['bonus'], ['wallet']), idempotent: true },\n redeemPromoCode: { invalidates: userKeys(['bonus'], ['wallet']), idempotent: true, sensitive: true },\n },\n loyalty: { redeem: { invalidates: userKeys(['loyalty'], ['wallet']), idempotent: true } },\n sportsbook: { createSession: { invalidates: none, sensitive: true } },\n}\n\n/**\n * Creates the iGaming query factories: one per read method, with the same name and the same input\n * as the method (`q.casino.listGames({ page })`). Each call returns `{ queryKey, queryFn }`, compatible\n * with TanStack Query v5's `useQuery`/`prefetchQuery`/`fetchQuery`. It makes no request.\n *\n * - Reads without a session (`casino.listGames/listCategories/listProviders/getGame`,\n * `bonus.listPublicOffers`): key `['enginex', 'public', namespace, method, input?]`.\n * - Player reads (the others): key `['enginex', 'user', userId, namespace, method, input?]`,\n * with the session's `userId` when the factory is called; without a session, `'anonymous'` and the `queryFn`\n * rejects with `UNAUTHENTICATED` without a request (the same if the session switches user before the `fetch`).\n * - `queryFn` forwards the context's `signal`: canceling the query aborts the `fetch`.\n * - None carries `staleTime`.\n * @param igaming - The object returned by `createIgaming(enginex)` (the object itself, not a copy).\n * @example\n * import { useQuery } from '@tanstack/react-query'\n * import { createIgamingQueries } from '@getenginex/sdk-igaming/query'\n *\n * const q = createIgamingQueries(igaming)\n * const games = useQuery(q.casino.listGames({ category: 'slots' }))\n * @throws {EnginexError} `CONFIGURATION_ERROR` if `igaming` did not come from `createIgaming` (e.g. a\n * `{ ...igaming }` copy). Identify with `isEnginexError(error, 'CONFIGURATION_ERROR')`.\n * @category Queries\n */\nexport function createIgamingQueries(igaming: IgamingClient): IgamingQueries {\n const scope = queryScope(igaming)\n const out: Record<string, Record<string, (input?: unknown) => unknown>> = {}\n const add = (\n table: Record<string, readonly string[]>,\n build: (namespace: string, method: string, input: unknown) => unknown,\n ) => {\n for (const [namespace, methods] of Object.entries(table)) {\n const factories = (out[namespace] ??= {})\n for (const method of methods) factories[method] = (input) => build(namespace, method, input)\n }\n }\n add(PUBLIC_READS, (namespace, method, input) =>\n scope.publicQuery(namespace, method, methodOf(igaming, namespace, method), input),\n )\n add(USER_READS, (namespace, method, input) =>\n scope.userQuery(namespace, method, methodOf(igaming, namespace, method), input),\n )\n return out as unknown as IgamingQueries\n}\n\n/**\n * Creates the iGaming mutations: one per write method, with the same name as the method\n * (`m.loyalty.redeem()`). Each call returns `{ mutationKey, mutationFn, invalidates }`, compatible\n * with TanStack Query v5's `useMutation`; `invalidates(input, result)` lists the prefixes the write\n * leaves stale (with the session's `userId` at call time; call it only after success):\n *\n * - `bonus.optIn/claim/redeemPromoCode` → `bonus` and `wallet` (the core's balance);\n * - `loyalty.redeem` → `loyalty` and `wallet`;\n * - `casino.launchGame` → `casino.listSessions`; `bonus.resolvePromoCode` and\n * `sportsbook.createSession` → nothing.\n *\n * `mutationKey` is `['enginex', namespace, method]`, without the input. The ones that send `Idempotency-Key`\n * (`bonus.optIn/claim/redeemPromoCode`, `loyalty.redeem`) reuse the key only after an ambiguous\n * failure (network, timeout, 5xx, `KEY_IN_USE` or `VALIDATION_ERROR` after a 2xx) with the same input,\n * on this options object (see the core's `createMutations`), and accept `{ idempotencyKey }` on the factory. The\n * ones that carry credentials in the input or the result (promo code, game URL, sportsbook\n * session) have `gcTime: 0`.\n * @param igaming - The object returned by `createIgaming(enginex)` (the object itself, not a copy).\n * @example\n * import { useMutation } from '@tanstack/react-query'\n * import { createIgamingMutations } from '@getenginex/sdk-igaming/query'\n *\n * const m = createIgamingMutations(igaming)\n * const redeem = m.loyalty.redeem()\n * const result = await redeem.mutationFn({ points: 500, redemptionType: 'bonus' })\n * for (const queryKey of redeem.invalidates({ points: 500, redemptionType: 'bonus' }, result)) {\n * await queryClient.invalidateQueries({ queryKey })\n * }\n * @throws {EnginexError} `CONFIGURATION_ERROR` if `igaming` did not come from `createIgaming`.\n * @category Queries\n */\nexport function createIgamingMutations(igaming: IgamingClient): IgamingMutations {\n const scope = queryScope(igaming)\n const out: Record<string, Record<string, (options?: { idempotencyKey?: string }) => unknown>> = {}\n for (const [namespace, methods] of Object.entries(WRITES)) {\n const factories = (out[namespace] ??= {})\n for (const [method, write] of Object.entries(methods)) {\n factories[method] = (options) => {\n const scoped: { idempotent?: boolean; idempotencyKey?: string; gcTime?: number } = {}\n if (write.idempotent === true) {\n scoped.idempotent = true\n if (options?.idempotencyKey !== undefined) scoped.idempotencyKey = options.idempotencyKey\n }\n if (write.sensitive === true) scoped.gcTime = 0\n return scope.mutation(\n namespace,\n method,\n methodOf(igaming, namespace, method),\n () => write.invalidates(scope),\n scoped,\n )\n }\n }\n }\n return out as unknown as IgamingMutations\n}\n"]}
1
+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,KAAmB,MAAA,EAAW,MAAA,CAAO,iBAAiB,OAAA,CAAQ,cAAA;AAAA,QAC7E;AACA,QAAA,IAAI,KAAA,CAAM,SAAA,KAAc,IAAA,EAAM,MAAA,CAAO,MAAA,GAAS,CAAA;AAC9C,QAAA,OAAO,KAAA,CAAM,QAAA;AAAA,UACX,SAAA;AAAA,UACA,MAAA;AAAA,UACA,QAAA,CAAS,OAAA,EAAS,SAAA,EAAW,MAAM,CAAA;AAAA,UACnC,MAAM,KAAA,CAAM,WAAA,CAAY,KAAK,CAAA;AAAA,UAC7B;AAAA,SACF;AAAA,MACF,CAAA;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,GAAA;AACT","file":"index.js","sourcesContent":["/**\n * iGaming query and mutation factories, compatible with TanStack Query v5 (`useQuery`,\n * `useMutation`, `prefetchQuery`), without depending on it. Same key conventions as\n * `@getenginex/sdk/query`.\n * @module @getenginex/sdk-igaming/query\n */\n\nimport type { CallOptions } from '@getenginex/sdk'\nimport {\n queryScope,\n type IdempotentMutationsOf,\n type MutationsOf,\n type QueriesOf,\n type QueryScope,\n} from '@getenginex/sdk/query'\nimport type { IgamingClient } from '../client'\nimport type { BetsApi } from '../modules/bets'\nimport type { BonusApi } from '../modules/bonus'\nimport type { CasinoApi } from '../modules/casino'\nimport type { LoyaltyApi } from '../modules/loyalty'\nimport type { MissionsApi } from '../modules/missions'\nimport type { ReferralsApi } from '../modules/referrals'\nimport type { SportsbookApi } from '../modules/sportsbook'\n\n/**\n * iGaming query factories, one per read method: `q.<namespace>.<method>(input)` returns\n * `{ queryKey, queryFn }`. Obtained with {@link createIgamingQueries}.\n * @category Queries\n */\nexport interface IgamingQueries {\n /** Catalog and lobby jackpots (public) and, with login, sessions, history and biggest winners. */\n readonly casino: QueriesOf<\n CasinoApi,\n | 'listGames'\n | 'listCategories'\n | 'listProviders'\n | 'getGame'\n | 'listJackpots'\n | 'listJackpotGames'\n | 'listSessions'\n | 'getHistory'\n | 'getBiggestWinners'\n >\n /** Public offers (no login) and, with login, offers, participations, bonus overview and positions. */\n readonly bonus: QueriesOf<\n BonusApi,\n | 'listPublicOffers'\n | 'listOffers'\n | 'getOffer'\n | 'listParticipations'\n | 'getParticipation'\n | 'getOverview'\n | 'listPositions'\n >\n /** Operator missions and the player's own. */\n readonly missions: QueriesOf<MissionsApi, 'list' | 'listMine'>\n /** Points balance, tier and benefits. */\n readonly loyalty: QueriesOf<LoyaltyApi, 'get'>\n /** Referral code, program rules, totals and history. */\n readonly referrals: QueriesOf<ReferralsApi, 'get' | 'listHistory'>\n /** The player's bets, a bet's details and its cash-out offer. */\n readonly bets: QueriesOf<BetsApi, 'list' | 'get' | 'getCashoutOffer'>\n}\n\n/**\n * iGaming mutations, one per write method: `m.<namespace>.<method>()` returns\n * `{ mutationKey, mutationFn, invalidates }`. Obtained with {@link createIgamingMutations}.\n * @category Queries\n */\nexport interface IgamingMutations {\n /** Game launch (`launchGame`, with `gcTime: 0`: the game URL carries credentials). */\n readonly casino: MutationsOf<CasinoApi, 'launchGame'>\n /** Opt-in, redemption (idempotent: they accept `{ idempotencyKey }`) and promo code check. */\n readonly bonus: IdempotentMutationsOf<BonusApi, 'optIn' | 'claim' | 'redeemPromoCode'> &\n MutationsOf<BonusApi, 'resolvePromoCode'>\n /** Points redemption (idempotent: it accepts `{ idempotencyKey }`). */\n readonly loyalty: IdempotentMutationsOf<LoyaltyApi, 'redeem'>\n /** Sportsbook session (`gcTime: 0`: the URL carries the operator token). */\n readonly sportsbook: MutationsOf<SportsbookApi, 'createSession'>\n /** Bet cash-out (idempotent: it accepts `{ idempotencyKey }`). */\n readonly bets: IdempotentMutationsOf<BetsApi, 'cashout'>\n}\n\ntype Method = (input: unknown, options?: CallOptions) => Promise<unknown>\n\n// Calls `igaming[namespace][method]` at request time (not at creation), keeping `this`.\nconst methodOf = (igaming: object, namespace: string, method: string) => (input: unknown, options: CallOptions) =>\n ((igaming as Record<string, Record<string, Method>>)[namespace]![method] as Method).call(\n (igaming as Record<string, unknown>)[namespace],\n input,\n options,\n )\n\n// Reads without a session (the method sends no token): `public` key, no `staleTime`.\nconst PUBLIC_READS = {\n casino: ['listGames', 'listCategories', 'listProviders', 'getGame', 'listJackpots', 'listJackpotGames'],\n bonus: ['listPublicOffers'],\n} as const\n\n// Player reads: `user` key with the session's `userId`.\nconst USER_READS = {\n casino: ['listSessions', 'getHistory', 'getBiggestWinners'],\n bonus: ['listOffers', 'getOffer', 'listParticipations', 'getParticipation', 'getOverview', 'listPositions'],\n missions: ['list', 'listMine'],\n loyalty: ['get'],\n referrals: ['get', 'listHistory'],\n bets: ['list', 'get', 'getCashoutOffer'],\n} as const\n\ntype Invalidation = (scope: QueryScope) => readonly (readonly unknown[])[]\nconst userKeys =\n (...prefixes: [namespace: string, method?: string][]): Invalidation =>\n (scope) =>\n prefixes.map(([namespace, method]) => scope.userPrefix(namespace, method))\nconst none: Invalidation = () => []\n\ninterface Write {\n /** What the write leaves stale. The core's prefixes (`wallet`) come from `scope.userPrefix`. */\n invalidates: Invalidation\n /** Sends `Idempotency-Key` (accepts `{ idempotencyKey }`). */\n idempotent?: boolean\n /** Entry or result with a credential: `gcTime: 0`. */\n sensitive?: boolean\n}\n\nconst WRITES: Record<string, Record<string, Write>> = {\n casino: { launchGame: { invalidates: userKeys(['casino', 'listSessions']), sensitive: true } },\n bonus: {\n resolvePromoCode: { invalidates: none, sensitive: true },\n optIn: { invalidates: userKeys(['bonus'], ['wallet']), idempotent: true },\n claim: { invalidates: userKeys(['bonus'], ['wallet']), idempotent: true },\n redeemPromoCode: { invalidates: userKeys(['bonus'], ['wallet']), idempotent: true, sensitive: true },\n },\n loyalty: { redeem: { invalidates: userKeys(['loyalty'], ['wallet']), idempotent: true } },\n sportsbook: { createSession: { invalidates: none, sensitive: true } },\n bets: { cashout: { invalidates: userKeys(['bets'], ['wallet']), idempotent: true } },\n}\n\n/**\n * Creates the iGaming query factories: one per read method, with the same name and the same input\n * as the method (`q.casino.listGames({ page })`). Each call returns `{ queryKey, queryFn }`, compatible\n * with TanStack Query v5's `useQuery`/`prefetchQuery`/`fetchQuery`. It makes no request.\n *\n * - Reads without a session (`casino.listGames/listCategories/listProviders/getGame/listJackpots/listJackpotGames`,\n * `bonus.listPublicOffers`): key `['enginex', 'public', namespace, method, input?]`.\n * - Player reads (the others): key `['enginex', 'user', userId, namespace, method, input?]`,\n * with the session's `userId` when the factory is called; without a session, `'anonymous'` and the `queryFn`\n * rejects with `UNAUTHENTICATED` without a request (the same if the session switches user before the `fetch`).\n * - `queryFn` forwards the context's `signal`: canceling the query aborts the `fetch`.\n * - None carries `staleTime`.\n * @param igaming - The object returned by `createIgaming(enginex)` (the object itself, not a copy).\n * @example\n * import { useQuery } from '@tanstack/react-query'\n * import { createIgamingQueries } from '@getenginex/sdk-igaming/query'\n *\n * const q = createIgamingQueries(igaming)\n * const games = useQuery(q.casino.listGames({ category: 'slots' }))\n * @throws {EnginexError} `CONFIGURATION_ERROR` if `igaming` did not come from `createIgaming` (e.g. a\n * `{ ...igaming }` copy). Identify with `isEnginexError(error, 'CONFIGURATION_ERROR')`.\n * @category Queries\n */\nexport function createIgamingQueries(igaming: IgamingClient): IgamingQueries {\n const scope = queryScope(igaming)\n const out: Record<string, Record<string, (input?: unknown) => unknown>> = {}\n const add = (\n table: Record<string, readonly string[]>,\n build: (namespace: string, method: string, input: unknown) => unknown,\n ) => {\n for (const [namespace, methods] of Object.entries(table)) {\n const factories = (out[namespace] ??= {})\n for (const method of methods) factories[method] = (input) => build(namespace, method, input)\n }\n }\n add(PUBLIC_READS, (namespace, method, input) =>\n scope.publicQuery(namespace, method, methodOf(igaming, namespace, method), input),\n )\n add(USER_READS, (namespace, method, input) =>\n scope.userQuery(namespace, method, methodOf(igaming, namespace, method), input),\n )\n return out as unknown as IgamingQueries\n}\n\n/**\n * Creates the iGaming mutations: one per write method, with the same name as the method\n * (`m.loyalty.redeem()`). Each call returns `{ mutationKey, mutationFn, invalidates }`, compatible\n * with TanStack Query v5's `useMutation`; `invalidates(input, result)` lists the prefixes the write\n * leaves stale (with the session's `userId` at call time; call it only after success):\n *\n * - `bonus.optIn/claim/redeemPromoCode` → `bonus` and `wallet` (the core's balance);\n * - `loyalty.redeem` → `loyalty` and `wallet`;\n * - `bets.cashout` → `bets` and `wallet`;\n * - `casino.launchGame` → `casino.listSessions`; `bonus.resolvePromoCode` and\n * `sportsbook.createSession` → nothing.\n *\n * `mutationKey` is `['enginex', namespace, method]`, without the input. The ones that send `Idempotency-Key`\n * (`bonus.optIn/claim/redeemPromoCode`, `loyalty.redeem`, `bets.cashout`) reuse the key only after an ambiguous\n * failure (network, timeout, 5xx, `KEY_IN_USE` or `VALIDATION_ERROR` after a 2xx) with the same input,\n * on this options object (see the core's `createMutations`), and accept `{ idempotencyKey }` on the factory. The\n * ones that carry credentials in the input or the result (promo code, game URL, sportsbook\n * session) have `gcTime: 0`.\n * @param igaming - The object returned by `createIgaming(enginex)` (the object itself, not a copy).\n * @example\n * import { useMutation } from '@tanstack/react-query'\n * import { createIgamingMutations } from '@getenginex/sdk-igaming/query'\n *\n * const m = createIgamingMutations(igaming)\n * const redeem = m.loyalty.redeem()\n * const result = await redeem.mutationFn({ points: 500, redemptionType: 'bonus' })\n * for (const queryKey of redeem.invalidates({ points: 500, redemptionType: 'bonus' }, result)) {\n * await queryClient.invalidateQueries({ queryKey })\n * }\n * @throws {EnginexError} `CONFIGURATION_ERROR` if `igaming` did not come from `createIgaming`.\n * @category Queries\n */\nexport function createIgamingMutations(igaming: IgamingClient): IgamingMutations {\n const scope = queryScope(igaming)\n const out: Record<string, Record<string, (options?: { idempotencyKey?: string }) => unknown>> = {}\n for (const [namespace, methods] of Object.entries(WRITES)) {\n const factories = (out[namespace] ??= {})\n for (const [method, write] of Object.entries(methods)) {\n factories[method] = (options) => {\n const scoped: { idempotent?: boolean; idempotencyKey?: string; gcTime?: number } = {}\n if (write.idempotent === true) {\n scoped.idempotent = true\n if (options?.idempotencyKey !== undefined) scoped.idempotencyKey = options.idempotencyKey\n }\n if (write.sensitive === true) scoped.gcTime = 0\n return scope.mutation(\n namespace,\n method,\n methodOf(igaming, namespace, method),\n () => write.invalidates(scope),\n scoped,\n )\n }\n }\n }\n return out as unknown as IgamingMutations\n}\n"]}
@@ -2,7 +2,129 @@
2
2
 
3
3
  var testing = require('@getenginex/sdk/testing');
4
4
 
5
- // src/testing/bonus.ts
5
+ // src/testing/bets.ts
6
+ var SEED = [
7
+ {
8
+ id: "mock-bet-3",
9
+ status: "BET_STATUS_PENDING",
10
+ stake: 2e3,
11
+ potential_return: 5400,
12
+ total_odds: 2.7,
13
+ created_at: "2026-09-03T18:00:00Z",
14
+ selections: [
15
+ {
16
+ event_name: "Flamengo x Palmeiras",
17
+ market_name: "Resultado final",
18
+ selection_name: "Flamengo",
19
+ odds: 2.7,
20
+ result: "SELECTION_RESULT_PENDING"
21
+ }
22
+ ]
23
+ },
24
+ {
25
+ id: "mock-bet-2",
26
+ status: "BET_STATUS_WON",
27
+ stake: 1e3,
28
+ potential_return: 3150,
29
+ total_odds: 3.15,
30
+ created_at: "2026-09-02T20:00:00Z",
31
+ selections: [
32
+ {
33
+ event_name: "Corinthians x Santos",
34
+ market_name: "Ambas marcam",
35
+ selection_name: "Sim",
36
+ odds: 1.75,
37
+ result: "SELECTION_RESULT_WON"
38
+ },
39
+ {
40
+ event_name: "Gr\xEAmio x Inter",
41
+ market_name: "Total de gols",
42
+ selection_name: "Mais de 2.5",
43
+ odds: 1.8,
44
+ result: "SELECTION_RESULT_WON"
45
+ }
46
+ ]
47
+ },
48
+ {
49
+ id: "mock-bet-1",
50
+ status: "BET_STATUS_LOST",
51
+ stake: 500,
52
+ potential_return: 950,
53
+ total_odds: 1.9,
54
+ created_at: "2026-09-01T15:30:00Z",
55
+ selections: [
56
+ {
57
+ event_name: "S\xE3o Paulo x Vasco",
58
+ market_name: "Resultado final",
59
+ selection_name: "Vasco",
60
+ odds: 1.9,
61
+ result: "SELECTION_RESULT_LOST"
62
+ }
63
+ ]
64
+ }
65
+ ];
66
+ function pageOf(req, items) {
67
+ const q = req.url.searchParams;
68
+ const page = Math.max(1, Number.parseInt(q.get("page") ?? "", 10) || 1);
69
+ const raw = Number.parseInt(q.get("limit") ?? "", 10);
70
+ const limit = raw >= 1 && raw <= 100 ? raw : 20;
71
+ return {
72
+ items: items.slice((page - 1) * limit, page * limit),
73
+ meta: { page, per_page: limit, total_pages: Math.ceil(items.length / limit), total_items: items.length }
74
+ };
75
+ }
76
+ var EPOCH = "1970-01-01T00:00:00Z";
77
+ function createBetsRoutes() {
78
+ const bets = SEED.map((bet) => ({ ...bet }));
79
+ const replays = /* @__PURE__ */ new Map();
80
+ const find = (req) => bets.find((bet) => bet.id === req.params?.betId);
81
+ const offerOf = (bet) => bet.status === "BET_STATUS_PENDING" ? Math.floor(Number(bet.potential_return) * 80 / 100) : 0;
82
+ const summary = (bet) => {
83
+ const { selections, ...rest } = bet;
84
+ return rest;
85
+ };
86
+ return {
87
+ "GET /api/v1/bets": (req) => {
88
+ const { items, meta } = pageOf(req, bets);
89
+ return testing.ok(items.map(summary), meta);
90
+ },
91
+ "GET /api/v1/bets/:betId": (req) => {
92
+ const bet = find(req);
93
+ return bet ? testing.ok(bet) : testing.fail(404, "BET_NOT_FOUND", "bet not found");
94
+ },
95
+ "GET /api/v1/bets/:betId/cashout": (req) => {
96
+ const bet = find(req);
97
+ if (!bet) return testing.fail(404, "BET_NOT_FOUND", "bet not found");
98
+ const amount = offerOf(bet);
99
+ return testing.ok({
100
+ bet_id: bet.id,
101
+ available: amount > 0,
102
+ cashout_amount: amount,
103
+ expires_at: amount > 0 ? new Date(Date.now() + 15e3).toISOString().replace(/\.\d{3}Z$/, "Z") : EPOCH
104
+ });
105
+ },
106
+ "POST /api/v1/bets/:betId/cashout": (req) => {
107
+ const key = req.headers.get("idempotency-key") ?? "";
108
+ if (key === "" || key !== key.trim())
109
+ return testing.fail(400, "INVALID_ARGUMENT", "Idempotency-Key must be normalized and non-empty");
110
+ const replayKey = `${String(req.params?.betId)}:${key}`;
111
+ const replay = replays.get(replayKey);
112
+ if (replay)
113
+ return replay.status === 200 ? testing.ok(replay.body) : testing.fail(replay.status, "FAILED_PRECONDITION", "cashout not available");
114
+ const bet = find(req);
115
+ if (!bet) return testing.fail(404, "BET_NOT_FOUND", "bet not found");
116
+ const amount = offerOf(bet);
117
+ if (amount === 0) {
118
+ replays.set(replayKey, { status: 422, body: null });
119
+ return testing.fail(422, "FAILED_PRECONDITION", "cashout not available");
120
+ }
121
+ bet.status = "BET_STATUS_CASHED_OUT";
122
+ const body = { bet_id: bet.id, cashout_amount: amount, status: "cashed_out" };
123
+ replays.set(replayKey, { status: 200, body });
124
+ return testing.ok(body);
125
+ }
126
+ };
127
+ }
6
128
  var uuid = (n) => `c0000000-0000-4000-8000-${String(n).padStart(12, "0")}`;
7
129
  var WINDOW = { starts_at: "2026-09-01T03:00:00Z", ends_at: "2027-01-01T03:00:00Z" };
8
130
  var brl = (minor) => ({ amount: String(minor), currency: "BRL" });
@@ -435,10 +557,49 @@ var WINNERS = [
435
557
  game_name: GAMES.find((g) => g.id === gameId)?.name,
436
558
  won_at: wonAt
437
559
  }));
560
+ var JACKPOT_CURRENCY = "BRL";
561
+ var SUPPORTED_CURRENCIES = /* @__PURE__ */ new Set(["BRL", "USD", "EUR", "CLP", "MXN", "ARS", "PEN", "COP"]);
562
+ var JACKPOTS = [
563
+ { id: `jackpot_${"a1".repeat(32)}`, name: "Mega Jackpot", amount_minor: "125000000", games: [0, 1, 2, 6] },
564
+ { id: `jackpot_${"b2".repeat(32)}`, name: "Jackpot Ao Vivo", amount_minor: "4875050", games: [3, 4, 5] }
565
+ ];
566
+ var JACKPOT_ID = /^jackpot_[0-9a-f]{64}$/;
567
+ var JACKPOT_CURSOR = /^[A-Za-z0-9_-]+$/;
568
+ function jackpotCurrency(req) {
569
+ const values = req.url.searchParams.getAll("currency");
570
+ if (values.length !== 1 || !SUPPORTED_CURRENCIES.has(values[0]))
571
+ return testing.fail(400, "INVALID_ARGUMENT", "a supported currency is required");
572
+ return values[0];
573
+ }
574
+ function listJackpotGames(req) {
575
+ const id = req.params?.jackpotId ?? "";
576
+ if (!JACKPOT_ID.test(id)) return testing.fail(400, "INVALID_ARGUMENT", "invalid jackpot ID");
577
+ const currency = jackpotCurrency(req);
578
+ if (currency instanceof Response) return currency;
579
+ const jackpot = JACKPOTS.find((j) => j.id === id);
580
+ if (currency !== JACKPOT_CURRENCY || !jackpot) return testing.fail(404, "NOT_FOUND", "jackpot not found");
581
+ const q = req.url.searchParams;
582
+ const device = (q.get("device") ?? "").trim().toLowerCase();
583
+ const page = q.get("page") === null ? 1 : Number(q.get("page"));
584
+ const limit = q.get("limit") === null ? 24 : Number(q.get("limit"));
585
+ if (!["", "mobile", "desktop"].includes(device) || !Number.isInteger(page) || page < 1 || !Number.isInteger(limit) || limit < 1 || limit > 48)
586
+ return testing.fail(400, "INVALID_ARGUMENT", "invalid jackpot games filters");
587
+ const cursor = q.get("cursor") ?? "";
588
+ if (page > 1 && cursor !== `page-${page}` || cursor !== "" && !JACKPOT_CURSOR.test(cursor))
589
+ return testing.fail(400, "INVALID_ARGUMENT", "invalid jackpot games cursor");
590
+ const games = jackpot.games.map((i) => GAMES[i]).filter((g) => device !== "mobile" || g.is_live !== true);
591
+ const items = games.slice((page - 1) * limit, page * limit);
592
+ const next = page * limit < games.length ? `page-${page + 1}` : "";
593
+ return testing.ok({
594
+ games: items,
595
+ mode: "verified",
596
+ pagination: { page, per_page: limit, has_next: next !== "", next_cursor: next }
597
+ });
598
+ }
438
599
  function json(body, status = 200) {
439
600
  return new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
440
601
  }
441
- function pageOf(req, items) {
602
+ function pageOf2(req, items) {
442
603
  const q = req.url.searchParams;
443
604
  const page = Math.max(1, Number.parseInt(q.get("page") ?? "", 10) || 1);
444
605
  const raw = Number.parseInt(q.get("limit") ?? "", 10);
@@ -465,11 +626,11 @@ function listGames(req) {
465
626
  (g) => (!category || g.category === category) && (!provider || g.provider === provider) && (!search || String(g.name).toLowerCase().includes(search)) && (ids.length === 0 || ids.includes(String(g.id)))
466
627
  );
467
628
  const sort = SORTS[q.get("sort") ?? ""];
468
- const { items, meta } = pageOf(req, sort ? [...games].sort(sort) : games);
629
+ const { items, meta } = pageOf2(req, sort ? [...games].sort(sort) : games);
469
630
  return json({
470
631
  success: true,
471
632
  data: items,
472
- availability: { status: "available", primary_provider_code: "pragmatic-play", missing: false },
633
+ availability: { status: "available", primary_provider_code: "pragmatic-play", missing: null },
473
634
  meta
474
635
  });
475
636
  }
@@ -503,6 +664,22 @@ function createCasinoRoutes() {
503
664
  }))
504
665
  ),
505
666
  "GET /api/v1/games/providers": () => testing.ok(PROVIDERS.map(([id, name]) => ({ id, name, game_count: GAMES.filter((g) => g.provider === id).length }))),
667
+ "GET /api/v1/games/jackpots": (req) => {
668
+ const currency = jackpotCurrency(req);
669
+ if (currency instanceof Response) return currency;
670
+ if (currency !== JACKPOT_CURRENCY) return testing.ok({ items: [], featured_id: "" });
671
+ return testing.ok({
672
+ items: JACKPOTS.map(({ id, name, amount_minor }) => ({
673
+ id,
674
+ name,
675
+ currency: JACKPOT_CURRENCY,
676
+ amount_minor,
677
+ decimal_places: 2
678
+ })),
679
+ featured_id: JACKPOTS[0].id
680
+ });
681
+ },
682
+ "GET /api/v1/games/jackpots/:jackpotId/games": listJackpotGames,
506
683
  "GET /api/v1/games/:gameId": (req) => {
507
684
  const game = GAMES.find((g) => g.id === req.params?.gameId);
508
685
  return game ? testing.ok(game) : testing.fail(404, "GAME_NOT_FOUND", "game not found");
@@ -537,11 +714,11 @@ function createCasinoRoutes() {
537
714
  });
538
715
  },
539
716
  "GET /api/v1/games/sessions": (req) => {
540
- const { items, meta } = pageOf(req, sessions);
717
+ const { items, meta } = pageOf2(req, sessions);
541
718
  return testing.ok(items, meta);
542
719
  },
543
720
  "GET /api/v1/games/history": (req) => {
544
- const { items, meta } = pageOf(req, HISTORY);
721
+ const { items, meta } = pageOf2(req, HISTORY);
545
722
  return testing.ok(items, meta);
546
723
  },
547
724
  "GET /api/v1/games/biggest-winners": (req) => {
@@ -586,7 +763,7 @@ function createLoyaltyRoutes() {
586
763
  }
587
764
  };
588
765
  }
589
- var EPOCH = "1970-01-01T00:00:00Z";
766
+ var EPOCH2 = "1970-01-01T00:00:00Z";
590
767
  var MISSIONS = [
591
768
  [
592
769
  "Aposte R$ 100 hoje",
@@ -610,10 +787,10 @@ var MISSIONS = [
610
787
  "free_spins",
611
788
  10,
612
789
  "2026-09-01T00:00:00Z",
613
- EPOCH
790
+ EPOCH2
614
791
  ],
615
- ["Jogue Aviator", "event", "play_game", 5, "", ["mock-game-7"], "bonus", 500, EPOCH, EPOCH],
616
- ["Primeiro dep\xF3sito do m\xEAs", "permanent", "deposit", 5e3, "", null, "free_bet", 1e3, EPOCH, EPOCH]
792
+ ["Jogue Aviator", "event", "play_game", 5, "", ["mock-game-7"], "bonus", 500, EPOCH2, EPOCH2],
793
+ ["Primeiro dep\xF3sito do m\xEAs", "permanent", "deposit", 5e3, "", null, "free_bet", 1e3, EPOCH2, EPOCH2]
617
794
  ].map(([name, type, objective, target, category, games, rewardType, rewardValue, from, to], i) => ({
618
795
  id: `mock-mission-${i + 1}`,
619
796
  name,
@@ -757,7 +934,8 @@ function createIgamingRoutes() {
757
934
  ...createSportsbookRoutes(),
758
935
  ...createMissionsRoutes(),
759
936
  ...createLoyaltyRoutes(),
760
- ...createReferralsRoutes()
937
+ ...createReferralsRoutes(),
938
+ ...createBetsRoutes()
761
939
  };
762
940
  }
763
941
  function withIgamingRoutes(options = {}) {