Reference / @getenginex/sdk/query / QueryScope
QueryScope
Pieces for building query and mutation factories over a client's session: the same ones createQueries/createMutations use. For SDK packages (@getenginex/sdk-igaming, @getenginex/sdk-predictions) and adapters (@getenginex/sdk-react), not for apps. Obtained with queryScope.
Methods
mutation()
mutation<
I,R>(namespace,method,call,invalidates,options?):EnginexMutationOptions<I,R>
Factory for a write: mutationKey ['enginex', namespace, method] and invalidates called by the adapter after success (use QueryScope.userPrefix to build the keys). With options.idempotent (methods that send Idempotency-Key), the key is only reused after an ambiguous failure (isAmbiguousFailure: NETWORK_ERROR, TIMEOUT, 5xx, KEY_IN_USE or VALIDATION_ERROR after a 2xx) with the same input, compared by content and not by object (a new mutate({ amount }) reuses the key), and only on this options object. Success, other 4xx, ABORTED and CONFIGURATION_ERROR release the key (whoever cancels and wants to retry passes idempotencyKey). In React, useEnginexMutation keeps the attempt per hook instance, so it survives the options being recreated on every render. options.idempotencyKey wins when given. The mutationFn rejects only with EnginexError. With options.gcTime, the mutation leaves the TanStack cache after that time (use 0 when the input or the result has credentials).
Type Parameters
I
I
R
R
Parameters
namespace
string
method
string
call
ScopedCall<I, R>
invalidates
(input, result) => readonly readonly unknown[][]
options?
Returns
EnginexMutationOptions<I, R>
Example
claim: () => scope.mutation('bonus', 'claim', (i, o) => igaming.bonus.claim(i, o), () => [
scope.userPrefix('bonus'),
scope.userPrefix('wallet'),
])publicKey()
publicKey(
namespace,method,input?):EnginexQueryKey
Public key: ['enginex', 'public', namespace, method, input?] (input omitted when undefined).
Parameters
namespace
string
method
string
input?
unknown
Returns
Example
scope.publicKey('casino', 'listGames', { page: 1 })publicQuery()
publicQuery<
I,T>(namespace,method,call,input,defaults?):EnginexQueryOptions<T>
Factory for a public read (no session). queryFn passes the context's signal on in options.signal. Without staleTime, unless given.
Type Parameters
I
I
T
T
Parameters
namespace
string
method
string
call
ScopedCall<I, T>
input
I
defaults?
staleTime?
number
Returns
Example
listGames: (input) => scope.publicQuery('casino', 'listGames', (i, o) => igaming.casino.listGames(i, o), input)userId()
userId():
string|undefined
The session's userId (the JWT sub) right now, or undefined without a session.
Returns
string | undefined
Example
const userId = scope.userId()userKey()
userKey(
namespace,method,input?):EnginexQueryKey
Key for the session's user right now: ['enginex', 'user', userId, namespace, method, input?], with 'anonymous' in place of the userId without a session.
Parameters
namespace
string
method
string
input?
unknown
Returns
Example
scope.userKey('wallet', 'getBalance')userPrefix()
userPrefix(
namespace,method?): readonlyunknown[]
Prefix for the session's user right now, for invalidates: ['enginex', 'user', userId, namespace] or, with method, ['enginex', 'user', userId, namespace, method] (matches any input).
Parameters
namespace
string
method?
string
Returns
readonly unknown[]
Example
scope.userPrefix('wallet') // balance, wallet and transactionsuserQuery()
userQuery<
I,T>(namespace,method,call,input):EnginexQueryOptions<T>
Factory for a user read: key with the session's userId at the moment of this call. The queryFn rejects with EnginexError UNAUTHENTICATED (status 401), without a request, when the session at fetch time is not that of the key's userId (no session, 'anonymous' key or another user): one player's data is never stored under another's key. The session is checked again when the request finishes: if the user changed during the request, the data is discarded and the queryFn rejects with UNAUTHENTICATED. An authenticated session without a sub in the JWT (e.g. a TokenStore with an opaque token) also rejects, with the message "session without a user identifier (sub)". Build the key again after login.
Type Parameters
I
I
T
T
Parameters
namespace
string
method
string
call
ScopedCall<I, T>
input
I
Returns
Example
getHistory: (input) => scope.userQuery('casino', 'getHistory', (i, o) => igaming.casino.getHistory(i, o), input)