@getenginex/sdk-igaming 0.5.0 → 0.7.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.
- package/CHANGELOG.md +40 -0
- package/README.md +44 -56
- package/dist/first-frame/index.cjs +4 -4
- package/dist/first-frame/index.cjs.map +1 -1
- package/dist/first-frame/index.d.cts +52 -52
- package/dist/first-frame/index.d.ts +52 -52
- package/dist/first-frame/index.js +4 -4
- package/dist/first-frame/index.js.map +1 -1
- package/dist/index.cjs +153 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +875 -692
- package/dist/index.d.ts +875 -692
- package/dist/index.js +153 -29
- package/dist/index.js.map +1 -1
- package/dist/query/index.cjs +1 -1
- package/dist/query/index.cjs.map +1 -1
- package/dist/query/index.d.cts +46 -46
- package/dist/query/index.d.ts +46 -46
- package/dist/query/index.js +1 -1
- package/dist/query/index.js.map +1 -1
- package/dist/testing/index.cjs +67 -5
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +37 -37
- package/dist/testing/index.d.ts +37 -37
- package/dist/testing/index.js +67 -5
- package/dist/testing/index.js.map +1 -1
- package/package.json +7 -7
package/dist/query/index.cjs
CHANGED
|
@@ -14,7 +14,7 @@ var PUBLIC_READS = {
|
|
|
14
14
|
};
|
|
15
15
|
var USER_READS = {
|
|
16
16
|
casino: ["listSessions", "getHistory", "getBiggestWinners"],
|
|
17
|
-
bonus: ["listOffers", "getOffer", "listParticipations", "getParticipation"],
|
|
17
|
+
bonus: ["listOffers", "getOffer", "listParticipations", "getParticipation", "getOverview", "listPositions"],
|
|
18
18
|
missions: ["list", "listMine"],
|
|
19
19
|
loyalty: ["get"],
|
|
20
20
|
referrals: ["get", "listHistory"]
|
package/dist/query/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/query/index.ts"],"names":["queryScope"],"mappings":";;;;;AAqEA,IAAM,QAAA,GAAW,CAAC,O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A,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 * Fábricas de query e mutation de iGaming, compatíveis com o TanStack Query v5 (`useQuery`,\n * `useMutation`, `prefetchQuery`), sem depender dele. Mesmas convenções de chave do\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 * Fábricas de query de iGaming, uma por método de leitura: `q.<namespace>.<método>(input)` devolve\n * `{ queryKey, queryFn }`. Obtidas com {@link createIgamingQueries}.\n * @category Queries\n */\nexport interface IgamingQueries {\n /** Catálogo (público) e, com login, sessões, histórico e maiores ganhadores. */\n readonly casino: QueriesOf<\n CasinoApi,\n 'listGames' | 'listCategories' | 'listProviders' | 'getGame' | 'listSessions' | 'getHistory' | 'getBiggestWinners'\n >\n /** Ofertas públicas (sem login) e, com login, ofertas e participações. */\n readonly bonus: QueriesOf<\n BonusApi,\n 'listPublicOffers' | 'listOffers' | 'getOffer' | 'listParticipations' | 'getParticipation'\n >\n /** Missões do operador e as do jogador. */\n readonly missions: QueriesOf<MissionsApi, 'list' | 'listMine'>\n /** Saldo de pontos, tier e benefícios. */\n readonly loyalty: QueriesOf<LoyaltyApi, 'get'>\n /** Código, link e histórico de indicações. */\n readonly referrals: QueriesOf<ReferralsApi, 'get' | 'listHistory'>\n}\n\n/**\n * Mutations de iGaming, uma por método de escrita: `m.<namespace>.<método>()` devolve\n * `{ mutationKey, mutationFn, invalidates }`. Obtidas com {@link createIgamingMutations}.\n * @category Queries\n */\nexport interface IgamingMutations {\n /** Abertura de jogo (`launchGame`, com `gcTime: 0`: a URL do jogo carrega credenciais). */\n readonly casino: MutationsOf<CasinoApi, 'launchGame'>\n /** Opt-in, resgate (idempotentes: aceitam `{ idempotencyKey }`) e conferência de promo code. */\n readonly bonus: IdempotentMutationsOf<BonusApi, 'optIn' | 'claim' | 'redeemPromoCode'> &\n MutationsOf<BonusApi, 'resolvePromoCode'>\n /** Resgate de pontos (idempotente: aceita `{ idempotencyKey }`). */\n readonly loyalty: IdempotentMutationsOf<LoyaltyApi, 'redeem'>\n /** Registro de código de indicação. */\n readonly referrals: MutationsOf<ReferralsApi, 'register'>\n /** Sessão do sportsbook (`gcTime: 0`: a URL carrega o token de operador). */\n readonly sportsbook: MutationsOf<SportsbookApi, 'createSession'>\n}\n\ntype Method = (input: unknown, options?: CallOptions) => Promise<unknown>\n\n// Chama `igaming[namespace][método]` na hora do request (não na criação), mantendo o `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// Leituras sem sessão (o método não manda token): chave `public`, sem `staleTime`.\nconst PUBLIC_READS = {\n casino: ['listGames', 'listCategories', 'listProviders', 'getGame'],\n bonus: ['listPublicOffers'],\n} as const\n\n// Leituras do jogador: chave `user` com o `userId` da sessão.\nconst USER_READS = {\n casino: ['listSessions', 'getHistory', 'getBiggestWinners'],\n bonus: ['listOffers', 'getOffer', 'listParticipations', 'getParticipation'],\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 /** O que a escrita deixa desatualizado. Os prefixos do core (`wallet`) saem de `scope.userPrefix`. */\n invalidates: Invalidation\n /** Manda `Idempotency-Key` (aceita `{ idempotencyKey }`). */\n idempotent?: boolean\n /** Entrada ou resultado com credencial: `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 referrals: { register: { invalidates: userKeys(['referrals']) } },\n sportsbook: { createSession: { invalidates: none, sensitive: true } },\n}\n\n/**\n * Cria as fábricas de query de iGaming: uma por método de leitura, com o mesmo nome e a mesma entrada\n * do método (`q.casino.listGames({ page })`). Cada chamada devolve `{ queryKey, queryFn }`, compatível\n * com `useQuery`/`prefetchQuery`/`fetchQuery` do TanStack Query v5. Não faz request.\n *\n * - Leituras sem sessão (`casino.listGames/listCategories/listProviders/getGame`,\n * `bonus.listPublicOffers`): chave `['enginex', 'public', namespace, método, input?]`.\n * - Leituras do jogador (as demais): chave `['enginex', 'user', userId, namespace, método, input?]`,\n * com o `userId` da sessão quando a fábrica é chamada; sem sessão, `'anonymous'` e o `queryFn`\n * rejeita com `UNAUTHENTICATED` sem request (o mesmo se a sessão mudar de usuário antes do `fetch`).\n * - `queryFn` repassa o `signal` do contexto: cancelar a query aborta o `fetch`.\n * - Nenhuma traz `staleTime`.\n * @param igaming - O objeto devolvido por `createIgaming(enginex)` (o próprio, não uma cópia).\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` se `igaming` não veio de `createIgaming` (ex.: uma\n * cópia `{ ...igaming }`). Identifique com `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 * Cria as mutations de iGaming: uma por método de escrita, com o mesmo nome do método\n * (`m.loyalty.redeem()`). Cada chamada devolve `{ mutationKey, mutationFn, invalidates }`, compatível\n * com `useMutation` do TanStack Query v5; `invalidates(input, result)` lista os prefixos que a escrita\n * deixa desatualizados (com o `userId` da sessão na hora da chamada; chame só depois do sucesso):\n *\n * - `bonus.optIn/claim/redeemPromoCode` → `bonus` e `wallet` (saldo do core);\n * - `loyalty.redeem` → `loyalty` e `wallet`; `referrals.register` → `referrals`;\n * - `casino.launchGame` → `casino.listSessions`; `bonus.resolvePromoCode` e\n * `sportsbook.createSession` → nada.\n *\n * `mutationKey` é `['enginex', namespace, método]`, sem a entrada. As que mandam `Idempotency-Key`\n * (`bonus.optIn/claim/redeemPromoCode`, `loyalty.redeem`) reusam a chave só depois de uma falha\n * ambígua (rede, timeout, 5xx, `KEY_IN_USE` ou `VALIDATION_ERROR` depois de 2xx) com a mesma entrada,\n * neste objeto de opções (veja `createMutations` do core), e aceitam `{ idempotencyKey }` na fábrica. As\n * que levam credenciais na entrada ou no resultado (código promocional, URL do jogo, sessão do\n * sportsbook) trazem `gcTime: 0`.\n * @param igaming - O objeto devolvido por `createIgaming(enginex)` (o próprio, não uma cópia).\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` se `igaming` não veio de `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":";;;;;AA2EA,IAAM,QAAA,GAAW,CAAC,OAAA,EAAiB,SAAA,EAAmB,MAAA,KAAmB,CAA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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 { 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, link 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 /** Referral code registration. */\n readonly referrals: MutationsOf<ReferralsApi, 'register'>\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 referrals: { register: { invalidates: userKeys(['referrals']) } },\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`; `referrals.register` → `referrals`;\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"]}
|
package/dist/query/index.d.cts
CHANGED
|
@@ -3,88 +3,88 @@ import { CasinoApi, BonusApi, LoyaltyApi, ReferralsApi, SportsbookApi, MissionsA
|
|
|
3
3
|
import '@getenginex/sdk';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* `useMutation`, `prefetchQuery`),
|
|
6
|
+
* iGaming query and mutation factories, compatible with TanStack Query v5 (`useQuery`,
|
|
7
|
+
* `useMutation`, `prefetchQuery`), without depending on it. Same key conventions as
|
|
8
8
|
* `@getenginex/sdk/query`.
|
|
9
9
|
* @module @getenginex/sdk-igaming/query
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
* `{ queryKey, queryFn }`.
|
|
13
|
+
* iGaming query factories, one per read method: `q.<namespace>.<method>(input)` returns
|
|
14
|
+
* `{ queryKey, queryFn }`. Obtained with {@link createIgamingQueries}.
|
|
15
15
|
* @category Queries
|
|
16
16
|
*/
|
|
17
17
|
interface IgamingQueries {
|
|
18
|
-
/**
|
|
18
|
+
/** Catalog (public) and, with login, sessions, history and biggest winners. */
|
|
19
19
|
readonly casino: QueriesOf<CasinoApi, 'listGames' | 'listCategories' | 'listProviders' | 'getGame' | 'listSessions' | 'getHistory' | 'getBiggestWinners'>;
|
|
20
|
-
/**
|
|
21
|
-
readonly bonus: QueriesOf<BonusApi, 'listPublicOffers' | 'listOffers' | 'getOffer' | 'listParticipations' | 'getParticipation'>;
|
|
22
|
-
/**
|
|
20
|
+
/** Public offers (no login) and, with login, offers, participations, bonus overview and positions. */
|
|
21
|
+
readonly bonus: QueriesOf<BonusApi, 'listPublicOffers' | 'listOffers' | 'getOffer' | 'listParticipations' | 'getParticipation' | 'getOverview' | 'listPositions'>;
|
|
22
|
+
/** Operator missions and the player's own. */
|
|
23
23
|
readonly missions: QueriesOf<MissionsApi, 'list' | 'listMine'>;
|
|
24
|
-
/**
|
|
24
|
+
/** Points balance, tier and benefits. */
|
|
25
25
|
readonly loyalty: QueriesOf<LoyaltyApi, 'get'>;
|
|
26
|
-
/**
|
|
26
|
+
/** Referral code, link and history. */
|
|
27
27
|
readonly referrals: QueriesOf<ReferralsApi, 'get' | 'listHistory'>;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
* `{ mutationKey, mutationFn, invalidates }`.
|
|
30
|
+
* iGaming mutations, one per write method: `m.<namespace>.<method>()` returns
|
|
31
|
+
* `{ mutationKey, mutationFn, invalidates }`. Obtained with {@link createIgamingMutations}.
|
|
32
32
|
* @category Queries
|
|
33
33
|
*/
|
|
34
34
|
interface IgamingMutations {
|
|
35
|
-
/**
|
|
35
|
+
/** Game launch (`launchGame`, with `gcTime: 0`: the game URL carries credentials). */
|
|
36
36
|
readonly casino: MutationsOf<CasinoApi, 'launchGame'>;
|
|
37
|
-
/** Opt-in,
|
|
37
|
+
/** Opt-in, redemption (idempotent: they accept `{ idempotencyKey }`) and promo code check. */
|
|
38
38
|
readonly bonus: IdempotentMutationsOf<BonusApi, 'optIn' | 'claim' | 'redeemPromoCode'> & MutationsOf<BonusApi, 'resolvePromoCode'>;
|
|
39
|
-
/**
|
|
39
|
+
/** Points redemption (idempotent: it accepts `{ idempotencyKey }`). */
|
|
40
40
|
readonly loyalty: IdempotentMutationsOf<LoyaltyApi, 'redeem'>;
|
|
41
|
-
/**
|
|
41
|
+
/** Referral code registration. */
|
|
42
42
|
readonly referrals: MutationsOf<ReferralsApi, 'register'>;
|
|
43
|
-
/**
|
|
43
|
+
/** Sportsbook session (`gcTime: 0`: the URL carries the operator token). */
|
|
44
44
|
readonly sportsbook: MutationsOf<SportsbookApi, 'createSession'>;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
47
|
+
* Creates the iGaming query factories: one per read method, with the same name and the same input
|
|
48
|
+
* as the method (`q.casino.listGames({ page })`). Each call returns `{ queryKey, queryFn }`, compatible
|
|
49
|
+
* with TanStack Query v5's `useQuery`/`prefetchQuery`/`fetchQuery`. It makes no request.
|
|
50
50
|
*
|
|
51
|
-
* -
|
|
52
|
-
* `bonus.listPublicOffers`):
|
|
53
|
-
* -
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* - `queryFn`
|
|
57
|
-
* -
|
|
58
|
-
* @param igaming -
|
|
51
|
+
* - Reads without a session (`casino.listGames/listCategories/listProviders/getGame`,
|
|
52
|
+
* `bonus.listPublicOffers`): key `['enginex', 'public', namespace, method, input?]`.
|
|
53
|
+
* - Player reads (the others): key `['enginex', 'user', userId, namespace, method, input?]`,
|
|
54
|
+
* with the session's `userId` when the factory is called; without a session, `'anonymous'` and the `queryFn`
|
|
55
|
+
* rejects with `UNAUTHENTICATED` without a request (the same if the session switches user before the `fetch`).
|
|
56
|
+
* - `queryFn` forwards the context's `signal`: canceling the query aborts the `fetch`.
|
|
57
|
+
* - None carries `staleTime`.
|
|
58
|
+
* @param igaming - The object returned by `createIgaming(enginex)` (the object itself, not a copy).
|
|
59
59
|
* @example
|
|
60
60
|
* import { useQuery } from '@tanstack/react-query'
|
|
61
61
|
* import { createIgamingQueries } from '@getenginex/sdk-igaming/query'
|
|
62
62
|
*
|
|
63
63
|
* const q = createIgamingQueries(igaming)
|
|
64
64
|
* const games = useQuery(q.casino.listGames({ category: 'slots' }))
|
|
65
|
-
* @throws {EnginexError} `CONFIGURATION_ERROR`
|
|
66
|
-
*
|
|
65
|
+
* @throws {EnginexError} `CONFIGURATION_ERROR` if `igaming` did not come from `createIgaming` (e.g. a
|
|
66
|
+
* `{ ...igaming }` copy). Identify with `isEnginexError(error, 'CONFIGURATION_ERROR')`.
|
|
67
67
|
* @category Queries
|
|
68
68
|
*/
|
|
69
69
|
declare function createIgamingQueries(igaming: IgamingClient): IgamingQueries;
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
72
|
-
* (`m.loyalty.redeem()`).
|
|
73
|
-
*
|
|
74
|
-
*
|
|
71
|
+
* Creates the iGaming mutations: one per write method, with the same name as the method
|
|
72
|
+
* (`m.loyalty.redeem()`). Each call returns `{ mutationKey, mutationFn, invalidates }`, compatible
|
|
73
|
+
* with TanStack Query v5's `useMutation`; `invalidates(input, result)` lists the prefixes the write
|
|
74
|
+
* leaves stale (with the session's `userId` at call time; call it only after success):
|
|
75
75
|
*
|
|
76
|
-
* - `bonus.optIn/claim/redeemPromoCode` → `bonus`
|
|
77
|
-
* - `loyalty.redeem` → `loyalty`
|
|
78
|
-
* - `casino.launchGame` → `casino.listSessions`; `bonus.resolvePromoCode`
|
|
79
|
-
* `sportsbook.createSession` →
|
|
76
|
+
* - `bonus.optIn/claim/redeemPromoCode` → `bonus` and `wallet` (the core's balance);
|
|
77
|
+
* - `loyalty.redeem` → `loyalty` and `wallet`; `referrals.register` → `referrals`;
|
|
78
|
+
* - `casino.launchGame` → `casino.listSessions`; `bonus.resolvePromoCode` and
|
|
79
|
+
* `sportsbook.createSession` → nothing.
|
|
80
80
|
*
|
|
81
|
-
* `mutationKey`
|
|
82
|
-
* (`bonus.optIn/claim/redeemPromoCode`, `loyalty.redeem`)
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* @param igaming -
|
|
81
|
+
* `mutationKey` is `['enginex', namespace, method]`, without the input. The ones that send `Idempotency-Key`
|
|
82
|
+
* (`bonus.optIn/claim/redeemPromoCode`, `loyalty.redeem`) reuse the key only after an ambiguous
|
|
83
|
+
* failure (network, timeout, 5xx, `KEY_IN_USE` or `VALIDATION_ERROR` after a 2xx) with the same input,
|
|
84
|
+
* on this options object (see the core's `createMutations`), and accept `{ idempotencyKey }` on the factory. The
|
|
85
|
+
* ones that carry credentials in the input or the result (promo code, game URL, sportsbook
|
|
86
|
+
* session) have `gcTime: 0`.
|
|
87
|
+
* @param igaming - The object returned by `createIgaming(enginex)` (the object itself, not a copy).
|
|
88
88
|
* @example
|
|
89
89
|
* import { useMutation } from '@tanstack/react-query'
|
|
90
90
|
* import { createIgamingMutations } from '@getenginex/sdk-igaming/query'
|
|
@@ -95,7 +95,7 @@ declare function createIgamingQueries(igaming: IgamingClient): IgamingQueries;
|
|
|
95
95
|
* for (const queryKey of redeem.invalidates({ points: 500, redemptionType: 'bonus' }, result)) {
|
|
96
96
|
* await queryClient.invalidateQueries({ queryKey })
|
|
97
97
|
* }
|
|
98
|
-
* @throws {EnginexError} `CONFIGURATION_ERROR`
|
|
98
|
+
* @throws {EnginexError} `CONFIGURATION_ERROR` if `igaming` did not come from `createIgaming`.
|
|
99
99
|
* @category Queries
|
|
100
100
|
*/
|
|
101
101
|
declare function createIgamingMutations(igaming: IgamingClient): IgamingMutations;
|
package/dist/query/index.d.ts
CHANGED
|
@@ -3,88 +3,88 @@ import { CasinoApi, BonusApi, LoyaltyApi, ReferralsApi, SportsbookApi, MissionsA
|
|
|
3
3
|
import '@getenginex/sdk';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* `useMutation`, `prefetchQuery`),
|
|
6
|
+
* iGaming query and mutation factories, compatible with TanStack Query v5 (`useQuery`,
|
|
7
|
+
* `useMutation`, `prefetchQuery`), without depending on it. Same key conventions as
|
|
8
8
|
* `@getenginex/sdk/query`.
|
|
9
9
|
* @module @getenginex/sdk-igaming/query
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
* `{ queryKey, queryFn }`.
|
|
13
|
+
* iGaming query factories, one per read method: `q.<namespace>.<method>(input)` returns
|
|
14
|
+
* `{ queryKey, queryFn }`. Obtained with {@link createIgamingQueries}.
|
|
15
15
|
* @category Queries
|
|
16
16
|
*/
|
|
17
17
|
interface IgamingQueries {
|
|
18
|
-
/**
|
|
18
|
+
/** Catalog (public) and, with login, sessions, history and biggest winners. */
|
|
19
19
|
readonly casino: QueriesOf<CasinoApi, 'listGames' | 'listCategories' | 'listProviders' | 'getGame' | 'listSessions' | 'getHistory' | 'getBiggestWinners'>;
|
|
20
|
-
/**
|
|
21
|
-
readonly bonus: QueriesOf<BonusApi, 'listPublicOffers' | 'listOffers' | 'getOffer' | 'listParticipations' | 'getParticipation'>;
|
|
22
|
-
/**
|
|
20
|
+
/** Public offers (no login) and, with login, offers, participations, bonus overview and positions. */
|
|
21
|
+
readonly bonus: QueriesOf<BonusApi, 'listPublicOffers' | 'listOffers' | 'getOffer' | 'listParticipations' | 'getParticipation' | 'getOverview' | 'listPositions'>;
|
|
22
|
+
/** Operator missions and the player's own. */
|
|
23
23
|
readonly missions: QueriesOf<MissionsApi, 'list' | 'listMine'>;
|
|
24
|
-
/**
|
|
24
|
+
/** Points balance, tier and benefits. */
|
|
25
25
|
readonly loyalty: QueriesOf<LoyaltyApi, 'get'>;
|
|
26
|
-
/**
|
|
26
|
+
/** Referral code, link and history. */
|
|
27
27
|
readonly referrals: QueriesOf<ReferralsApi, 'get' | 'listHistory'>;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
* `{ mutationKey, mutationFn, invalidates }`.
|
|
30
|
+
* iGaming mutations, one per write method: `m.<namespace>.<method>()` returns
|
|
31
|
+
* `{ mutationKey, mutationFn, invalidates }`. Obtained with {@link createIgamingMutations}.
|
|
32
32
|
* @category Queries
|
|
33
33
|
*/
|
|
34
34
|
interface IgamingMutations {
|
|
35
|
-
/**
|
|
35
|
+
/** Game launch (`launchGame`, with `gcTime: 0`: the game URL carries credentials). */
|
|
36
36
|
readonly casino: MutationsOf<CasinoApi, 'launchGame'>;
|
|
37
|
-
/** Opt-in,
|
|
37
|
+
/** Opt-in, redemption (idempotent: they accept `{ idempotencyKey }`) and promo code check. */
|
|
38
38
|
readonly bonus: IdempotentMutationsOf<BonusApi, 'optIn' | 'claim' | 'redeemPromoCode'> & MutationsOf<BonusApi, 'resolvePromoCode'>;
|
|
39
|
-
/**
|
|
39
|
+
/** Points redemption (idempotent: it accepts `{ idempotencyKey }`). */
|
|
40
40
|
readonly loyalty: IdempotentMutationsOf<LoyaltyApi, 'redeem'>;
|
|
41
|
-
/**
|
|
41
|
+
/** Referral code registration. */
|
|
42
42
|
readonly referrals: MutationsOf<ReferralsApi, 'register'>;
|
|
43
|
-
/**
|
|
43
|
+
/** Sportsbook session (`gcTime: 0`: the URL carries the operator token). */
|
|
44
44
|
readonly sportsbook: MutationsOf<SportsbookApi, 'createSession'>;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
47
|
+
* Creates the iGaming query factories: one per read method, with the same name and the same input
|
|
48
|
+
* as the method (`q.casino.listGames({ page })`). Each call returns `{ queryKey, queryFn }`, compatible
|
|
49
|
+
* with TanStack Query v5's `useQuery`/`prefetchQuery`/`fetchQuery`. It makes no request.
|
|
50
50
|
*
|
|
51
|
-
* -
|
|
52
|
-
* `bonus.listPublicOffers`):
|
|
53
|
-
* -
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* - `queryFn`
|
|
57
|
-
* -
|
|
58
|
-
* @param igaming -
|
|
51
|
+
* - Reads without a session (`casino.listGames/listCategories/listProviders/getGame`,
|
|
52
|
+
* `bonus.listPublicOffers`): key `['enginex', 'public', namespace, method, input?]`.
|
|
53
|
+
* - Player reads (the others): key `['enginex', 'user', userId, namespace, method, input?]`,
|
|
54
|
+
* with the session's `userId` when the factory is called; without a session, `'anonymous'` and the `queryFn`
|
|
55
|
+
* rejects with `UNAUTHENTICATED` without a request (the same if the session switches user before the `fetch`).
|
|
56
|
+
* - `queryFn` forwards the context's `signal`: canceling the query aborts the `fetch`.
|
|
57
|
+
* - None carries `staleTime`.
|
|
58
|
+
* @param igaming - The object returned by `createIgaming(enginex)` (the object itself, not a copy).
|
|
59
59
|
* @example
|
|
60
60
|
* import { useQuery } from '@tanstack/react-query'
|
|
61
61
|
* import { createIgamingQueries } from '@getenginex/sdk-igaming/query'
|
|
62
62
|
*
|
|
63
63
|
* const q = createIgamingQueries(igaming)
|
|
64
64
|
* const games = useQuery(q.casino.listGames({ category: 'slots' }))
|
|
65
|
-
* @throws {EnginexError} `CONFIGURATION_ERROR`
|
|
66
|
-
*
|
|
65
|
+
* @throws {EnginexError} `CONFIGURATION_ERROR` if `igaming` did not come from `createIgaming` (e.g. a
|
|
66
|
+
* `{ ...igaming }` copy). Identify with `isEnginexError(error, 'CONFIGURATION_ERROR')`.
|
|
67
67
|
* @category Queries
|
|
68
68
|
*/
|
|
69
69
|
declare function createIgamingQueries(igaming: IgamingClient): IgamingQueries;
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
72
|
-
* (`m.loyalty.redeem()`).
|
|
73
|
-
*
|
|
74
|
-
*
|
|
71
|
+
* Creates the iGaming mutations: one per write method, with the same name as the method
|
|
72
|
+
* (`m.loyalty.redeem()`). Each call returns `{ mutationKey, mutationFn, invalidates }`, compatible
|
|
73
|
+
* with TanStack Query v5's `useMutation`; `invalidates(input, result)` lists the prefixes the write
|
|
74
|
+
* leaves stale (with the session's `userId` at call time; call it only after success):
|
|
75
75
|
*
|
|
76
|
-
* - `bonus.optIn/claim/redeemPromoCode` → `bonus`
|
|
77
|
-
* - `loyalty.redeem` → `loyalty`
|
|
78
|
-
* - `casino.launchGame` → `casino.listSessions`; `bonus.resolvePromoCode`
|
|
79
|
-
* `sportsbook.createSession` →
|
|
76
|
+
* - `bonus.optIn/claim/redeemPromoCode` → `bonus` and `wallet` (the core's balance);
|
|
77
|
+
* - `loyalty.redeem` → `loyalty` and `wallet`; `referrals.register` → `referrals`;
|
|
78
|
+
* - `casino.launchGame` → `casino.listSessions`; `bonus.resolvePromoCode` and
|
|
79
|
+
* `sportsbook.createSession` → nothing.
|
|
80
80
|
*
|
|
81
|
-
* `mutationKey`
|
|
82
|
-
* (`bonus.optIn/claim/redeemPromoCode`, `loyalty.redeem`)
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* @param igaming -
|
|
81
|
+
* `mutationKey` is `['enginex', namespace, method]`, without the input. The ones that send `Idempotency-Key`
|
|
82
|
+
* (`bonus.optIn/claim/redeemPromoCode`, `loyalty.redeem`) reuse the key only after an ambiguous
|
|
83
|
+
* failure (network, timeout, 5xx, `KEY_IN_USE` or `VALIDATION_ERROR` after a 2xx) with the same input,
|
|
84
|
+
* on this options object (see the core's `createMutations`), and accept `{ idempotencyKey }` on the factory. The
|
|
85
|
+
* ones that carry credentials in the input or the result (promo code, game URL, sportsbook
|
|
86
|
+
* session) have `gcTime: 0`.
|
|
87
|
+
* @param igaming - The object returned by `createIgaming(enginex)` (the object itself, not a copy).
|
|
88
88
|
* @example
|
|
89
89
|
* import { useMutation } from '@tanstack/react-query'
|
|
90
90
|
* import { createIgamingMutations } from '@getenginex/sdk-igaming/query'
|
|
@@ -95,7 +95,7 @@ declare function createIgamingQueries(igaming: IgamingClient): IgamingQueries;
|
|
|
95
95
|
* for (const queryKey of redeem.invalidates({ points: 500, redemptionType: 'bonus' }, result)) {
|
|
96
96
|
* await queryClient.invalidateQueries({ queryKey })
|
|
97
97
|
* }
|
|
98
|
-
* @throws {EnginexError} `CONFIGURATION_ERROR`
|
|
98
|
+
* @throws {EnginexError} `CONFIGURATION_ERROR` if `igaming` did not come from `createIgaming`.
|
|
99
99
|
* @category Queries
|
|
100
100
|
*/
|
|
101
101
|
declare function createIgamingMutations(igaming: IgamingClient): IgamingMutations;
|
package/dist/query/index.js
CHANGED
|
@@ -12,7 +12,7 @@ var PUBLIC_READS = {
|
|
|
12
12
|
};
|
|
13
13
|
var USER_READS = {
|
|
14
14
|
casino: ["listSessions", "getHistory", "getBiggestWinners"],
|
|
15
|
-
bonus: ["listOffers", "getOffer", "listParticipations", "getParticipation"],
|
|
15
|
+
bonus: ["listOffers", "getOffer", "listParticipations", "getParticipation", "getOverview", "listPositions"],
|
|
16
16
|
missions: ["list", "listMine"],
|
|
17
17
|
loyalty: ["get"],
|
|
18
18
|
referrals: ["get", "listHistory"]
|
package/dist/query/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/query/index.ts"],"names":[],"mappings":";;;AAqEA,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,C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utation`, `prefetchQuery`), sem depender dele. Mesmas convenções de chave do\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 * Fábricas de query de iGaming, uma por método de leitura: `q.<namespace>.<método>(input)` devolve\n * `{ queryKey, queryFn }`. Obtidas com {@link createIgamingQueries}.\n * @category Queries\n */\nexport interface IgamingQueries {\n /** Catálogo (público) e, com login, sessões, histórico e maiores ganhadores. */\n readonly casino: QueriesOf<\n CasinoApi,\n 'listGames' | 'listCategories' | 'listProviders' | 'getGame' | 'listSessions' | 'getHistory' | 'getBiggestWinners'\n >\n /** Ofertas públicas (sem login) e, com login, ofertas e participações. */\n readonly bonus: QueriesOf<\n BonusApi,\n 'listPublicOffers' | 'listOffers' | 'getOffer' | 'listParticipations' | 'getParticipation'\n >\n /** Missões do operador e as do jogador. */\n readonly missions: QueriesOf<MissionsApi, 'list' | 'listMine'>\n /** Saldo de pontos, tier e benefícios. */\n readonly loyalty: QueriesOf<LoyaltyApi, 'get'>\n /** Código, link e histórico de indicações. */\n readonly referrals: QueriesOf<ReferralsApi, 'get' | 'listHistory'>\n}\n\n/**\n * Mutations de iGaming, uma por método de escrita: `m.<namespace>.<método>()` devolve\n * `{ mutationKey, mutationFn, invalidates }`. Obtidas com {@link createIgamingMutations}.\n * @category Queries\n */\nexport interface IgamingMutations {\n /** Abertura de jogo (`launchGame`, com `gcTime: 0`: a URL do jogo carrega credenciais). */\n readonly casino: MutationsOf<CasinoApi, 'launchGame'>\n /** Opt-in, resgate (idempotentes: aceitam `{ idempotencyKey }`) e conferência de promo code. */\n readonly bonus: IdempotentMutationsOf<BonusApi, 'optIn' | 'claim' | 'redeemPromoCode'> &\n MutationsOf<BonusApi, 'resolvePromoCode'>\n /** Resgate de pontos (idempotente: aceita `{ idempotencyKey }`). */\n readonly loyalty: IdempotentMutationsOf<LoyaltyApi, 'redeem'>\n /** Registro de código de indicação. */\n readonly referrals: MutationsOf<ReferralsApi, 'register'>\n /** Sessão do sportsbook (`gcTime: 0`: a URL carrega o token de operador). */\n readonly sportsbook: MutationsOf<SportsbookApi, 'createSession'>\n}\n\ntype Method = (input: unknown, options?: CallOptions) => Promise<unknown>\n\n// Chama `igaming[namespace][método]` na hora do request (não na criação), mantendo o `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// Leituras sem sessão (o método não manda token): chave `public`, sem `staleTime`.\nconst PUBLIC_READS = {\n casino: ['listGames', 'listCategories', 'listProviders', 'getGame'],\n bonus: ['listPublicOffers'],\n} as const\n\n// Leituras do jogador: chave `user` com o `userId` da sessão.\nconst USER_READS = {\n casino: ['listSessions', 'getHistory', 'getBiggestWinners'],\n bonus: ['listOffers', 'getOffer', 'listParticipations', 'getParticipation'],\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 /** O que a escrita deixa desatualizado. Os prefixos do core (`wallet`) saem de `scope.userPrefix`. */\n invalidates: Invalidation\n /** Manda `Idempotency-Key` (aceita `{ idempotencyKey }`). */\n idempotent?: boolean\n /** Entrada ou resultado com credencial: `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 referrals: { register: { invalidates: userKeys(['referrals']) } },\n sportsbook: { createSession: { invalidates: none, sensitive: true } },\n}\n\n/**\n * Cria as fábricas de query de iGaming: uma por método de leitura, com o mesmo nome e a mesma entrada\n * do método (`q.casino.listGames({ page })`). Cada chamada devolve `{ queryKey, queryFn }`, compatível\n * com `useQuery`/`prefetchQuery`/`fetchQuery` do TanStack Query v5. Não faz request.\n *\n * - Leituras sem sessão (`casino.listGames/listCategories/listProviders/getGame`,\n * `bonus.listPublicOffers`): chave `['enginex', 'public', namespace, método, input?]`.\n * - Leituras do jogador (as demais): chave `['enginex', 'user', userId, namespace, método, input?]`,\n * com o `userId` da sessão quando a fábrica é chamada; sem sessão, `'anonymous'` e o `queryFn`\n * rejeita com `UNAUTHENTICATED` sem request (o mesmo se a sessão mudar de usuário antes do `fetch`).\n * - `queryFn` repassa o `signal` do contexto: cancelar a query aborta o `fetch`.\n * - Nenhuma traz `staleTime`.\n * @param igaming - O objeto devolvido por `createIgaming(enginex)` (o próprio, não uma cópia).\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` se `igaming` não veio de `createIgaming` (ex.: uma\n * cópia `{ ...igaming }`). Identifique com `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 * Cria as mutations de iGaming: uma por método de escrita, com o mesmo nome do método\n * (`m.loyalty.redeem()`). Cada chamada devolve `{ mutationKey, mutationFn, invalidates }`, compatível\n * com `useMutation` do TanStack Query v5; `invalidates(input, result)` lista os prefixos que a escrita\n * deixa desatualizados (com o `userId` da sessão na hora da chamada; chame só depois do sucesso):\n *\n * - `bonus.optIn/claim/redeemPromoCode` → `bonus` e `wallet` (saldo do core);\n * - `loyalty.redeem` → `loyalty` e `wallet`; `referrals.register` → `referrals`;\n * - `casino.launchGame` → `casino.listSessions`; `bonus.resolvePromoCode` e\n * `sportsbook.createSession` → nada.\n *\n * `mutationKey` é `['enginex', namespace, método]`, sem a entrada. As que mandam `Idempotency-Key`\n * (`bonus.optIn/claim/redeemPromoCode`, `loyalty.redeem`) reusam a chave só depois de uma falha\n * ambígua (rede, timeout, 5xx, `KEY_IN_USE` ou `VALIDATION_ERROR` depois de 2xx) com a mesma entrada,\n * neste objeto de opções (veja `createMutations` do core), e aceitam `{ idempotencyKey }` na fábrica. As\n * que levam credenciais na entrada ou no resultado (código promocional, URL do jogo, sessão do\n * sportsbook) trazem `gcTime: 0`.\n * @param igaming - O objeto devolvido por `createIgaming(enginex)` (o próprio, não uma cópia).\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` se `igaming` não veio de `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":[],"mappings":";;;AA2EA,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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AA,EAAS,SAAA,EAAW,MAAM,GAAG,KAAK;AAAA,GAChF;AACA,EAAA,OAAO,GAAA;AACT;AAiCO,SAAS,uBAAuB,OAAA,EAA0C;AAC/E,EAAA,MAAM,KAAA,GAAQ,WAAW,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.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, link 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 /** Referral code registration. */\n readonly referrals: MutationsOf<ReferralsApi, 'register'>\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 referrals: { register: { invalidates: userKeys(['referrals']) } },\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`; `referrals.register` → `referrals`;\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"]}
|
package/dist/testing/index.cjs
CHANGED
|
@@ -237,6 +237,25 @@ function createBonusRoutes() {
|
|
|
237
237
|
return p;
|
|
238
238
|
};
|
|
239
239
|
const nextId = () => uuid(1e3 + ++seq);
|
|
240
|
+
const positions = () => participations.filter((p) => p.reward_grant).map((p) => {
|
|
241
|
+
const grant = p.reward_grant;
|
|
242
|
+
return {
|
|
243
|
+
position_id: uuid(2e3 + participations.indexOf(p)),
|
|
244
|
+
campaign_id: p.campaign_id,
|
|
245
|
+
currency: "BRL",
|
|
246
|
+
decimal_places: 2,
|
|
247
|
+
granted: grant.granted.amount,
|
|
248
|
+
restricted: grant.balance.amount,
|
|
249
|
+
converted: "0",
|
|
250
|
+
required: grant.wagering.required.amount,
|
|
251
|
+
wagered: "0",
|
|
252
|
+
remaining: grant.wagering.required.amount,
|
|
253
|
+
state: "open",
|
|
254
|
+
terminal_action: null,
|
|
255
|
+
expires_at: grant.expires_at,
|
|
256
|
+
created_at: p.completed.completed_at
|
|
257
|
+
};
|
|
258
|
+
});
|
|
240
259
|
return {
|
|
241
260
|
"GET /api/v1/bonus-campaigns/public-offers": (req) => cursorPage(req, "offers", CATALOG),
|
|
242
261
|
"GET /api/v1/bonus-campaigns/offers": (req) => cursorPage(req, "offers", CATALOG),
|
|
@@ -273,6 +292,14 @@ function createBonusRoutes() {
|
|
|
273
292
|
}
|
|
274
293
|
delete p.qualified;
|
|
275
294
|
p.completed = { completed_at: now() };
|
|
295
|
+
p.reward_grant = {
|
|
296
|
+
state: "CAMPAIGN_PLAYER_REWARD_GRANT_STATE_ACTIVE",
|
|
297
|
+
granted: brl(5e3),
|
|
298
|
+
balance: brl(5e3),
|
|
299
|
+
converted: { currency: "BRL" },
|
|
300
|
+
expires_at: new Date(Date.now() + 7 * 864e5).toISOString(),
|
|
301
|
+
wagering: { required: brl(15e4), accumulated: { currency: "BRL" } }
|
|
302
|
+
};
|
|
276
303
|
return testing.ok({ participation: p });
|
|
277
304
|
}),
|
|
278
305
|
"POST /api/v1/bonus-campaigns/promo-codes/resolve": (req) => {
|
|
@@ -284,9 +311,9 @@ function createBonusRoutes() {
|
|
|
284
311
|
if (!o) return notFound("promo code");
|
|
285
312
|
return testing.ok({ offer: o, localized_content: localized(o, typeof locale === "string" ? locale : "") });
|
|
286
313
|
},
|
|
287
|
-
//
|
|
288
|
-
// header
|
|
289
|
-
//
|
|
314
|
+
// Without the transport's idempotency middleware (the body holds a secret): the handler only requires the
|
|
315
|
+
// header and passes the key on to the bonus service, which does the command's idempotency — here, the same
|
|
316
|
+
// key returns the participation created by it.
|
|
290
317
|
"POST /api/v1/bonus-campaigns/promo-codes/redeem": (req) => {
|
|
291
318
|
const key = req.headers.get("idempotency-key") ?? "";
|
|
292
319
|
if (key === "" || key !== key.trim()) {
|
|
@@ -305,6 +332,35 @@ function createBonusRoutes() {
|
|
|
305
332
|
return created(p);
|
|
306
333
|
},
|
|
307
334
|
"GET /api/v1/bonus-campaigns/participations": (req) => cursorPage(req, "participations", participations),
|
|
335
|
+
// The player's bonus balance, derived from the grants of the claimed participations (plain JSON, not
|
|
336
|
+
// protojson: every key present, money as text, absent dates as `null`).
|
|
337
|
+
"GET /api/v1/bonus/overview": () => {
|
|
338
|
+
const open = positions().filter((row) => row.state === "open");
|
|
339
|
+
if (open.length === 0) return testing.ok({ currencies: [], as_of: now() });
|
|
340
|
+
const total = open.reduce((sum, row) => sum + Number(row.restricted), 0);
|
|
341
|
+
return testing.ok({
|
|
342
|
+
currencies: [
|
|
343
|
+
{
|
|
344
|
+
currency: "BRL",
|
|
345
|
+
decimal_places: 2,
|
|
346
|
+
restricted_total: String(total),
|
|
347
|
+
expiring_7d: String(total),
|
|
348
|
+
open_positions: open.length,
|
|
349
|
+
next_expires_at: open.map((row) => String(row.expires_at)).sort()[0],
|
|
350
|
+
converted: "0",
|
|
351
|
+
converted_campaigns: 0
|
|
352
|
+
}
|
|
353
|
+
],
|
|
354
|
+
as_of: now()
|
|
355
|
+
});
|
|
356
|
+
},
|
|
357
|
+
"GET /api/v1/bonus/positions": (req) => {
|
|
358
|
+
const state = req.url.searchParams.get("state") ?? "";
|
|
359
|
+
if (state !== "" && state !== "open" && state !== "terminal") {
|
|
360
|
+
return testing.fail(400, "INVALID_ARGUMENT", "state must be open or terminal");
|
|
361
|
+
}
|
|
362
|
+
return testing.ok({ rows: positions().filter((row) => state === "" || row.state === state), next_cursor: "" });
|
|
363
|
+
},
|
|
308
364
|
"GET /api/v1/bonus-campaigns/participations/:participationId": (req) => {
|
|
309
365
|
const bad = badId(req, "participationId");
|
|
310
366
|
if (bad) return bad;
|
|
@@ -357,7 +413,7 @@ var HISTORY = [
|
|
|
357
413
|
round_id: roundId,
|
|
358
414
|
type,
|
|
359
415
|
amount: String(amount),
|
|
360
|
-
//
|
|
416
|
+
// the gateway sends int64 as text
|
|
361
417
|
currency: "BRL",
|
|
362
418
|
currency_decimal_places: 2,
|
|
363
419
|
created_at: createdAt
|
|
@@ -470,7 +526,13 @@ function createCasinoRoutes() {
|
|
|
470
526
|
url.searchParams.set("token", `mock-launch-token-${seq}`);
|
|
471
527
|
url.searchParams.set("lang", launchLanguage(req, body));
|
|
472
528
|
if (body.is_demo === true) url.searchParams.set("demo", "true");
|
|
473
|
-
return testing.ok({
|
|
529
|
+
return testing.ok({
|
|
530
|
+
session_id: session.id,
|
|
531
|
+
game_url: url.href,
|
|
532
|
+
launch_target: "iframe",
|
|
533
|
+
provider_code: game.provider,
|
|
534
|
+
expires_at: new Date(Date.now() + 36e5).toISOString().replace(/\.\d{3}Z$/, "Z")
|
|
535
|
+
});
|
|
474
536
|
},
|
|
475
537
|
"GET /api/v1/games/sessions": (req) => {
|
|
476
538
|
const { items, meta } = pageOf(req, sessions);
|