@getenginex/sdk-igaming 0.0.0-stage → 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.
@@ -0,0 +1,103 @@
1
+ import { MutationsOf, IdempotentMutationsOf, QueriesOf } from '@getenginex/sdk/query';
2
+ import { CasinoApi, BonusApi, LoyaltyApi, ReferralsApi, SportsbookApi, MissionsApi, IgamingClient } from '../index.cjs';
3
+ import '@getenginex/sdk';
4
+
5
+ /**
6
+ * iGaming query and mutation factories, compatible with TanStack Query v5 (`useQuery`,
7
+ * `useMutation`, `prefetchQuery`), without depending on it. Same key conventions as
8
+ * `@getenginex/sdk/query`.
9
+ * @module @getenginex/sdk-igaming/query
10
+ */
11
+
12
+ /**
13
+ * iGaming query factories, one per read method: `q.<namespace>.<method>(input)` returns
14
+ * `{ queryKey, queryFn }`. Obtained with {@link createIgamingQueries}.
15
+ * @category Queries
16
+ */
17
+ interface IgamingQueries {
18
+ /** Catalog (public) and, with login, sessions, history and biggest winners. */
19
+ readonly casino: QueriesOf<CasinoApi, 'listGames' | 'listCategories' | 'listProviders' | 'getGame' | 'listSessions' | 'getHistory' | 'getBiggestWinners'>;
20
+ /** Public offers (no login) and, with login, offers and participations. */
21
+ readonly bonus: QueriesOf<BonusApi, 'listPublicOffers' | 'listOffers' | 'getOffer' | 'listParticipations' | 'getParticipation'>;
22
+ /** Operator missions and the player's own. */
23
+ readonly missions: QueriesOf<MissionsApi, 'list' | 'listMine'>;
24
+ /** Points balance, tier and benefits. */
25
+ readonly loyalty: QueriesOf<LoyaltyApi, 'get'>;
26
+ /** Referral code, link and history. */
27
+ readonly referrals: QueriesOf<ReferralsApi, 'get' | 'listHistory'>;
28
+ }
29
+ /**
30
+ * iGaming mutations, one per write method: `m.<namespace>.<method>()` returns
31
+ * `{ mutationKey, mutationFn, invalidates }`. Obtained with {@link createIgamingMutations}.
32
+ * @category Queries
33
+ */
34
+ interface IgamingMutations {
35
+ /** Game launch (`launchGame`, with `gcTime: 0`: the game URL carries credentials). */
36
+ readonly casino: MutationsOf<CasinoApi, 'launchGame'>;
37
+ /** Opt-in, redemption (idempotent: they accept `{ idempotencyKey }`) and promo code check. */
38
+ readonly bonus: IdempotentMutationsOf<BonusApi, 'optIn' | 'claim' | 'redeemPromoCode'> & MutationsOf<BonusApi, 'resolvePromoCode'>;
39
+ /** Points redemption (idempotent: it accepts `{ idempotencyKey }`). */
40
+ readonly loyalty: IdempotentMutationsOf<LoyaltyApi, 'redeem'>;
41
+ /** Referral code registration. */
42
+ readonly referrals: MutationsOf<ReferralsApi, 'register'>;
43
+ /** Sportsbook session (`gcTime: 0`: the URL carries the operator token). */
44
+ readonly sportsbook: MutationsOf<SportsbookApi, 'createSession'>;
45
+ }
46
+ /**
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
+ *
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
+ * @example
60
+ * import { useQuery } from '@tanstack/react-query'
61
+ * import { createIgamingQueries } from '@getenginex/sdk-igaming/query'
62
+ *
63
+ * const q = createIgamingQueries(igaming)
64
+ * const games = useQuery(q.casino.listGames({ category: 'slots' }))
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
+ * @category Queries
68
+ */
69
+ declare function createIgamingQueries(igaming: IgamingClient): IgamingQueries;
70
+ /**
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
+ *
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
+ *
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
+ * @example
89
+ * import { useMutation } from '@tanstack/react-query'
90
+ * import { createIgamingMutations } from '@getenginex/sdk-igaming/query'
91
+ *
92
+ * const m = createIgamingMutations(igaming)
93
+ * const redeem = m.loyalty.redeem()
94
+ * const result = await redeem.mutationFn({ points: 500, redemptionType: 'bonus' })
95
+ * for (const queryKey of redeem.invalidates({ points: 500, redemptionType: 'bonus' }, result)) {
96
+ * await queryClient.invalidateQueries({ queryKey })
97
+ * }
98
+ * @throws {EnginexError} `CONFIGURATION_ERROR` if `igaming` did not come from `createIgaming`.
99
+ * @category Queries
100
+ */
101
+ declare function createIgamingMutations(igaming: IgamingClient): IgamingMutations;
102
+
103
+ export { type IgamingMutations, type IgamingQueries, createIgamingMutations, createIgamingQueries };
@@ -0,0 +1,103 @@
1
+ import { MutationsOf, IdempotentMutationsOf, QueriesOf } from '@getenginex/sdk/query';
2
+ import { CasinoApi, BonusApi, LoyaltyApi, ReferralsApi, SportsbookApi, MissionsApi, IgamingClient } from '../index.js';
3
+ import '@getenginex/sdk';
4
+
5
+ /**
6
+ * iGaming query and mutation factories, compatible with TanStack Query v5 (`useQuery`,
7
+ * `useMutation`, `prefetchQuery`), without depending on it. Same key conventions as
8
+ * `@getenginex/sdk/query`.
9
+ * @module @getenginex/sdk-igaming/query
10
+ */
11
+
12
+ /**
13
+ * iGaming query factories, one per read method: `q.<namespace>.<method>(input)` returns
14
+ * `{ queryKey, queryFn }`. Obtained with {@link createIgamingQueries}.
15
+ * @category Queries
16
+ */
17
+ interface IgamingQueries {
18
+ /** Catalog (public) and, with login, sessions, history and biggest winners. */
19
+ readonly casino: QueriesOf<CasinoApi, 'listGames' | 'listCategories' | 'listProviders' | 'getGame' | 'listSessions' | 'getHistory' | 'getBiggestWinners'>;
20
+ /** Public offers (no login) and, with login, offers and participations. */
21
+ readonly bonus: QueriesOf<BonusApi, 'listPublicOffers' | 'listOffers' | 'getOffer' | 'listParticipations' | 'getParticipation'>;
22
+ /** Operator missions and the player's own. */
23
+ readonly missions: QueriesOf<MissionsApi, 'list' | 'listMine'>;
24
+ /** Points balance, tier and benefits. */
25
+ readonly loyalty: QueriesOf<LoyaltyApi, 'get'>;
26
+ /** Referral code, link and history. */
27
+ readonly referrals: QueriesOf<ReferralsApi, 'get' | 'listHistory'>;
28
+ }
29
+ /**
30
+ * iGaming mutations, one per write method: `m.<namespace>.<method>()` returns
31
+ * `{ mutationKey, mutationFn, invalidates }`. Obtained with {@link createIgamingMutations}.
32
+ * @category Queries
33
+ */
34
+ interface IgamingMutations {
35
+ /** Game launch (`launchGame`, with `gcTime: 0`: the game URL carries credentials). */
36
+ readonly casino: MutationsOf<CasinoApi, 'launchGame'>;
37
+ /** Opt-in, redemption (idempotent: they accept `{ idempotencyKey }`) and promo code check. */
38
+ readonly bonus: IdempotentMutationsOf<BonusApi, 'optIn' | 'claim' | 'redeemPromoCode'> & MutationsOf<BonusApi, 'resolvePromoCode'>;
39
+ /** Points redemption (idempotent: it accepts `{ idempotencyKey }`). */
40
+ readonly loyalty: IdempotentMutationsOf<LoyaltyApi, 'redeem'>;
41
+ /** Referral code registration. */
42
+ readonly referrals: MutationsOf<ReferralsApi, 'register'>;
43
+ /** Sportsbook session (`gcTime: 0`: the URL carries the operator token). */
44
+ readonly sportsbook: MutationsOf<SportsbookApi, 'createSession'>;
45
+ }
46
+ /**
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
+ *
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
+ * @example
60
+ * import { useQuery } from '@tanstack/react-query'
61
+ * import { createIgamingQueries } from '@getenginex/sdk-igaming/query'
62
+ *
63
+ * const q = createIgamingQueries(igaming)
64
+ * const games = useQuery(q.casino.listGames({ category: 'slots' }))
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
+ * @category Queries
68
+ */
69
+ declare function createIgamingQueries(igaming: IgamingClient): IgamingQueries;
70
+ /**
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
+ *
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
+ *
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
+ * @example
89
+ * import { useMutation } from '@tanstack/react-query'
90
+ * import { createIgamingMutations } from '@getenginex/sdk-igaming/query'
91
+ *
92
+ * const m = createIgamingMutations(igaming)
93
+ * const redeem = m.loyalty.redeem()
94
+ * const result = await redeem.mutationFn({ points: 500, redemptionType: 'bonus' })
95
+ * for (const queryKey of redeem.invalidates({ points: 500, redemptionType: 'bonus' }, result)) {
96
+ * await queryClient.invalidateQueries({ queryKey })
97
+ * }
98
+ * @throws {EnginexError} `CONFIGURATION_ERROR` if `igaming` did not come from `createIgaming`.
99
+ * @category Queries
100
+ */
101
+ declare function createIgamingMutations(igaming: IgamingClient): IgamingMutations;
102
+
103
+ export { type IgamingMutations, type IgamingQueries, createIgamingMutations, createIgamingQueries };
@@ -0,0 +1,81 @@
1
+ import { queryScope } from '@getenginex/sdk/query';
2
+
3
+ // src/query/index.ts
4
+ var methodOf = (igaming, namespace, method) => (input, options) => igaming[namespace][method].call(
5
+ igaming[namespace],
6
+ input,
7
+ options
8
+ );
9
+ var PUBLIC_READS = {
10
+ casino: ["listGames", "listCategories", "listProviders", "getGame"],
11
+ bonus: ["listPublicOffers"]
12
+ };
13
+ var USER_READS = {
14
+ casino: ["listSessions", "getHistory", "getBiggestWinners"],
15
+ bonus: ["listOffers", "getOffer", "listParticipations", "getParticipation"],
16
+ missions: ["list", "listMine"],
17
+ loyalty: ["get"],
18
+ referrals: ["get", "listHistory"]
19
+ };
20
+ var userKeys = (...prefixes) => (scope) => prefixes.map(([namespace, method]) => scope.userPrefix(namespace, method));
21
+ var none = () => [];
22
+ var WRITES = {
23
+ casino: { launchGame: { invalidates: userKeys(["casino", "listSessions"]), sensitive: true } },
24
+ bonus: {
25
+ resolvePromoCode: { invalidates: none, sensitive: true },
26
+ optIn: { invalidates: userKeys(["bonus"], ["wallet"]), idempotent: true },
27
+ claim: { invalidates: userKeys(["bonus"], ["wallet"]), idempotent: true },
28
+ redeemPromoCode: { invalidates: userKeys(["bonus"], ["wallet"]), idempotent: true, sensitive: true }
29
+ },
30
+ loyalty: { redeem: { invalidates: userKeys(["loyalty"], ["wallet"]), idempotent: true } },
31
+ referrals: { register: { invalidates: userKeys(["referrals"]) } },
32
+ sportsbook: { createSession: { invalidates: none, sensitive: true } }
33
+ };
34
+ function createIgamingQueries(igaming) {
35
+ const scope = queryScope(igaming);
36
+ const out = {};
37
+ const add = (table, build) => {
38
+ for (const [namespace, methods] of Object.entries(table)) {
39
+ const factories = out[namespace] ??= {};
40
+ for (const method of methods) factories[method] = (input) => build(namespace, method, input);
41
+ }
42
+ };
43
+ add(
44
+ PUBLIC_READS,
45
+ (namespace, method, input) => scope.publicQuery(namespace, method, methodOf(igaming, namespace, method), input)
46
+ );
47
+ add(
48
+ USER_READS,
49
+ (namespace, method, input) => scope.userQuery(namespace, method, methodOf(igaming, namespace, method), input)
50
+ );
51
+ return out;
52
+ }
53
+ function createIgamingMutations(igaming) {
54
+ const scope = queryScope(igaming);
55
+ const out = {};
56
+ for (const [namespace, methods] of Object.entries(WRITES)) {
57
+ const factories = out[namespace] ??= {};
58
+ for (const [method, write] of Object.entries(methods)) {
59
+ factories[method] = (options) => {
60
+ const scoped = {};
61
+ if (write.idempotent === true) {
62
+ scoped.idempotent = true;
63
+ if (options?.idempotencyKey !== void 0) scoped.idempotencyKey = options.idempotencyKey;
64
+ }
65
+ if (write.sensitive === true) scoped.gcTime = 0;
66
+ return scope.mutation(
67
+ namespace,
68
+ method,
69
+ methodOf(igaming, namespace, method),
70
+ () => write.invalidates(scope),
71
+ scoped
72
+ );
73
+ };
74
+ }
75
+ }
76
+ return out;
77
+ }
78
+
79
+ export { createIgamingMutations, createIgamingQueries };
80
+ //# sourceMappingURL=index.js.map
81
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,CAAA;AAAA,EAClE,KAAA,EAAO,CAAC,kBAAkB;AAC5B,CAAA;AAGA,IAAM,UAAA,GAAa;AAAA,EACjB,MAAA,EAAQ,CAAC,cAAA,EAAgB,YAAA,EAAc,mBAAmB,CAAA;AAAA,E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AC/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 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"]}