@getenginex/sdk-igaming 0.5.0 → 0.6.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 +24 -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 +39 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +725 -691
- package/dist/index.d.ts +725 -691
- package/dist/index.js +39 -28
- package/dist/index.js.map +1 -1
- package/dist/query/index.cjs.map +1 -1
- package/dist/query/index.d.cts +45 -45
- package/dist/query/index.d.ts +45 -45
- package/dist/query/index.js.map +1 -1
- package/dist/testing/index.cjs +11 -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 +11 -5
- package/dist/testing/index.js.map +1 -1
- package/package.json +5 -5
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,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,E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,EAAA,OAAO,GAAA;AACT;AAiCO,SAAS,uBAAuB,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 * 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":";;;;;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,CAAA;AAAA,EAClE,KAAA,EAAO,CAAC,kBAAkB;AAC5B,CAAA;AAGA,IAAM,UAAA,GAAa;AAAA,EACjB,MAAA,EAAQ,CAAC,cAAA,EAAgB,YAAA,EAAc,mBAA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uB,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 { 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 and participations. */\n readonly bonus: QueriesOf<\n BonusApi,\n 'listPublicOffers' | 'listOffers' | 'getOffer' | 'listParticipations' | 'getParticipation'\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'],\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
|
-
/**
|
|
20
|
+
/** Public offers (no login) and, with login, offers and participations. */
|
|
21
21
|
readonly bonus: QueriesOf<BonusApi, 'listPublicOffers' | 'listOffers' | 'getOffer' | 'listParticipations' | 'getParticipation'>;
|
|
22
|
-
/**
|
|
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
|
-
/**
|
|
20
|
+
/** Public offers (no login) and, with login, offers and participations. */
|
|
21
21
|
readonly bonus: QueriesOf<BonusApi, 'listPublicOffers' | 'listOffers' | 'getOffer' | 'listParticipations' | 'getParticipation'>;
|
|
22
|
-
/**
|
|
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.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;A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AA,UAC7B;AAAA,SACF;AAAA,MACF,CAAA;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,GAAA;AACT","file":"index.js","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":[],"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,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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 and participations. */\n readonly bonus: QueriesOf<\n BonusApi,\n 'listPublicOffers' | 'listOffers' | 'getOffer' | 'listParticipations' | 'getParticipation'\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'],\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
|
@@ -284,9 +284,9 @@ function createBonusRoutes() {
|
|
|
284
284
|
if (!o) return notFound("promo code");
|
|
285
285
|
return testing.ok({ offer: o, localized_content: localized(o, typeof locale === "string" ? locale : "") });
|
|
286
286
|
},
|
|
287
|
-
//
|
|
288
|
-
// header
|
|
289
|
-
//
|
|
287
|
+
// Without the transport's idempotency middleware (the body holds a secret): the handler only requires the
|
|
288
|
+
// header and passes the key on to the bonus service, which does the command's idempotency — here, the same
|
|
289
|
+
// key returns the participation created by it.
|
|
290
290
|
"POST /api/v1/bonus-campaigns/promo-codes/redeem": (req) => {
|
|
291
291
|
const key = req.headers.get("idempotency-key") ?? "";
|
|
292
292
|
if (key === "" || key !== key.trim()) {
|
|
@@ -357,7 +357,7 @@ var HISTORY = [
|
|
|
357
357
|
round_id: roundId,
|
|
358
358
|
type,
|
|
359
359
|
amount: String(amount),
|
|
360
|
-
//
|
|
360
|
+
// the gateway sends int64 as text
|
|
361
361
|
currency: "BRL",
|
|
362
362
|
currency_decimal_places: 2,
|
|
363
363
|
created_at: createdAt
|
|
@@ -470,7 +470,13 @@ function createCasinoRoutes() {
|
|
|
470
470
|
url.searchParams.set("token", `mock-launch-token-${seq}`);
|
|
471
471
|
url.searchParams.set("lang", launchLanguage(req, body));
|
|
472
472
|
if (body.is_demo === true) url.searchParams.set("demo", "true");
|
|
473
|
-
return testing.ok({
|
|
473
|
+
return testing.ok({
|
|
474
|
+
session_id: session.id,
|
|
475
|
+
game_url: url.href,
|
|
476
|
+
launch_target: "iframe",
|
|
477
|
+
provider_code: game.provider,
|
|
478
|
+
expires_at: new Date(Date.now() + 36e5).toISOString().replace(/\.\d{3}Z$/, "Z")
|
|
479
|
+
});
|
|
474
480
|
},
|
|
475
481
|
"GET /api/v1/games/sessions": (req) => {
|
|
476
482
|
const { items, meta } = pageOf(req, sessions);
|