@getenginex/sdk-igaming
v0.7.0
Published
EngineX casino, bonuses, missions, loyalty, referrals and FIRST sportsbook on top of the @getenginex/sdk client
Maintainers
Readme
@getenginex/sdk-igaming
Casino, bonuses, missions, loyalty, referrals and the FIRST sportsbook for EngineX, built on the @getenginex/sdk client.
Namespaces: casino (catalog, launch game, sessions, history, winners ranking), bonus (campaigns, opt-in, claim, promo
codes), missions, loyalty (points, tier, redeem), referrals and sportsbook (FIRST session for the iframe).
Install
Install it next to the core. The core is a peer dependency, so the app has a single copy of it (one session, tenant, hooks and validation for everything):
npm i @getenginex/sdk @getenginex/sdk-igamingPeer: @getenginex/sdk >=0.6.0 <1.0.0. A client created by a core copy with an incompatible transport contract makes
createIgaming throw CONFIGURATION_ERROR. zod 4 is shared with the core: keep a single zod 4 in the project.
Quick start
import { createEnginexClient } from '@getenginex/sdk'
import { createIgaming } from '@getenginex/sdk-igaming'
export const enginex = createEnginexClient({ locale: 'pt-BR' })
export const igaming = createIgaming(enginex)
const games = await igaming.casino.listGames({ category: 'slots', perPage: 24 })
const { gameUrl } = await igaming.casino.launchGame({ gameId: games.items[0].id }) // requires login
const offers = await igaming.bonus.listOffers() // requires login
await igaming.bonus.redeemPromoCode({ code: 'WELCOME' }, { idempotencyKey: crypto.randomUUID() })gameUrl carries the game session token: the SDK returns it only as a result (never in hooks), so do not log it.
createIgaming creates no session, tenant or transport of its own and makes no request: every method goes through the app's
client. Create one per client (one per app in the browser; one per request on the server). A value that is not a client
created by createEnginexClient (for example a copy { ...enginex }) is rejected with CONFIGURATION_ERROR.
Entry points
| Subpath | Purpose |
| --- | --- |
| @getenginex/sdk-igaming | createIgaming and the casino, bonus, missions, loyalty, referrals and sportsbook namespaces |
| @getenginex/sdk-igaming/testing | Mock routes for iGaming (withIgamingRoutes) on top of the core's createMockFetch |
| @getenginex/sdk-igaming/first-frame | Origin-checked postMessage events and commands for the FIRST sportsbook iframe |
| @getenginex/sdk-igaming/query | Query and mutation factories for TanStack Query v5 |
Queries and mutations
import { createIgamingMutations, createIgamingQueries } from '@getenginex/sdk-igaming/query'
const q = createIgamingQueries(igaming)
const m = createIgamingMutations(igaming)
q.casino.listGames({ page: 1 }) // { queryKey: ['enginex', 'public', 'casino', 'listGames', { page: 1 }], queryFn }
m.loyalty.redeem() // { mutationKey, mutationFn, invalidates }: loyalty and the core walletThe casino catalog and public bonus offers use the public key; other reads use the user key. bonus.optIn/claim/redeemPromoCode
and loyalty.redeem send an Idempotency-Key that is reused only after an ambiguous failure, with the same input and in the
same mutation (Idempotency). The entry requires @getenginex/sdk >=0.6.0 and is not
in the bundle of anyone who imports only the main entry.
FIRST iframe events
import { connectFirstFrame } from '@getenginex/sdk-igaming/first-frame'
const frame = connectFirstFrame(iframe, {
onBetPlaced: () => void enginex.wallet.getBalance().then(showBalance),
onLoginRequired: () => openLoginModal(),
})
frame.dispose() // on unmountDetails in Sportsbook (FIRST).
Testing
withIgamingRoutes adds the iGaming mock routes to the core's createMockFetch:
import { createEnginexClient } from '@getenginex/sdk'
import { createMockFetch } from '@getenginex/sdk/testing'
import { createIgaming } from '@getenginex/sdk-igaming'
import { withIgamingRoutes } from '@getenginex/sdk-igaming/testing'
const enginex = createEnginexClient({
baseUrl: 'https://gateway.test', // in Node: absolute baseUrl + tenantHost (optional in the browser)
tenantHost: 'casino.test',
fetch: createMockFetch(withIgamingRoutes({ withdrawalOtp: true })),
})
const igaming = createIgaming(enginex)Core routes still apply and options.routes win over the iGaming ones. To build the routes object by hand, use
createIgamingRoutes(). See Testing and mocks.
Versions
While the major version is 0, minor versions may contain breaking changes and patch versions do not. Pin a tilde range
(for example ~0.x.0, with the minor you use) to take only fixes, and read the upgrade guide and the changelog before upgrading.
