@getenginex/sdk-igaming 0.10.0 → 0.11.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 CHANGED
@@ -1,5 +1,48 @@
1
1
  # @getenginex/sdk-igaming
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e186fba: New `club` namespace (IE-666): the casino club the player used to call directly. `getOverview`, `listHistory`,
8
+ `listTournaments`, `listRelatedTournaments`, `getTournament` and `getRanking` read the program, the player's balances,
9
+ activities, missions, store, history and club tournaments; `setMembership`, `play` (also opens a mission chest),
10
+ `redeem` and `registerForTournament` are idempotent writes (`Idempotency-Key`, up to 128 characters, replayed by the
11
+ club service). The routes answer without the envelope, in protojson or (`?relatedTo=`) plain JSON: omitted or `null`
12
+ lists become `[]`, absent messages `null`, absent dates (epoch, Go's zero time) `null`, codes come in lowercase and
13
+ a repeated id keeps the first occurrence. Money is strict also under `'warn'` (negative, fraction, exponent or
14
+ ≥ 2^53 rejects). `createIgamingQueries`/`createIgamingMutations` get the `club` factories and `/testing` mocks
15
+ every route with in-memory state.
16
+
17
+ The `club` writes keep the `Idempotency-Key` after a 409 or a 429 and release it only on 400/403/404/422: the club
18
+ answers a duplicate still in flight with a plain 409, so releasing it there would let the next tap pay twice
19
+ (core `>=0.12.0` for the factories). `keepsClubIdempotencyKey(error)` exposes the rule to apps that persist their
20
+ own key.
21
+
22
+ An invalid `announcedAmount` on an external tournament prize no longer rejects the whole `listTournaments` page under
23
+ `'warn'`: it is reported and only that prize is dropped (never rounded; `'strict'` still rejects).
24
+
25
+ The `club` query keys end with `{ locale }` (the client's locale): after `setLocale` the program is fetched again
26
+ with the new `termsLocale` instead of a join recording consent under the old terms.
27
+
28
+ `club.play`/`redeem` invalidate only `club.getOverview`, `club.listHistory`, `bonus` and `wallet` (not the
29
+ tournaments nor the rankings), and the four club writes carry `invalidatesOnError`: a 409 refreshes the overview (and,
30
+ for `registerForTournament`, the tournaments).
31
+
32
+ The `/testing` club mock records a chest as `sourceKind: 'chest'` (the real value), accepts
33
+ `createIgamingRoutes({ club: { program: 'paused' | 'disabled' } })` (also through `withIgamingRoutes`), serves the
34
+ related page with a `null` title and Go zero times, and reproduces writes that fail in the middle (keys starting with
35
+ `inflight-` answer 409 once, `lost-` apply and answer 503 once).
36
+
37
+ The club input checks count ids in UTF-8 bytes (the gateway's limit is 128 bytes), and an `idempotencyKey` must be
38
+ printable ASCII (a header value travels as bytes: an emoji would make `fetch` throw).
39
+
40
+ ## 0.10.1
41
+
42
+ ### Patch Changes
43
+
44
+ - 07cffe0: Omitted and `null` lists (IE-659): the protobuf `list()` helper now reads `null` as `[]` as well as an omitted list, so the bonus cursor pages (`listPublicOffers`, `listOffers`, `listParticipations`, `listPositions`), `getOverview` and every nested campaign list never hand out `null`; `toCursorPage` also falls back to `[]` when a core older than 0.11.1 lets a malformed list through in `'warn'`. `casino.listCategories`, `listProviders` and `getBiggestWinners` read a `null` body as `[]`, and `referrals.listHistory` reads a `null` pagination as absent. With core 0.11.1, a `null` jackpot-games pagination in `'warn'` no longer fails with `UNKNOWN` (a `TypeError`).
45
+
3
46
  ## 0.10.0
4
47
 
5
48
  ### Minor Changes
package/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # @getenginex/sdk-igaming
2
2
 
3
- Casino, bonuses, missions, loyalty, referrals and the FIRST sportsbook for EngineX, built on the `@getenginex/sdk` client.
3
+ Casino, casino club, bonuses, missions, loyalty, referrals and the FIRST sportsbook for EngineX, built on the `@getenginex/sdk` client.
4
4
 
5
5
  [Docs](https://game-engine-io.github.io/enginex-frontend-sdk/igaming/) · [Português](https://game-engine-io.github.io/enginex-frontend-sdk/pt/igaming/) · [Español](https://game-engine-io.github.io/enginex-frontend-sdk/es/igaming/)
6
6
 
7
- Namespaces: `casino` (catalog, lobby jackpots, launch game, sessions, history, winners ranking), `bonus` (campaigns, opt-in,
7
+ Namespaces: `casino` (catalog, lobby jackpots, launch game, sessions, history, winners ranking), `club` (casino club: program, wheel, mission chests, coin store,
8
+ history, tournaments), `bonus` (campaigns, opt-in,
8
9
  claim, promo codes), `missions`, `loyalty` (points, tier, redeem), `referrals`, `sportsbook` (FIRST session for the iframe)
9
10
  and `bets` (sportsbook bet history and cash-out).
10
11
 
@@ -45,7 +46,7 @@ created by `createEnginexClient` (for example a copy `{ ...enginex }`) is reject
45
46
 
46
47
  | Subpath | Purpose |
47
48
  | --- | --- |
48
- | `@getenginex/sdk-igaming` | `createIgaming` and the casino, bonus, missions, loyalty, referrals, sportsbook and bets namespaces |
49
+ | `@getenginex/sdk-igaming` | `createIgaming` and the casino, club, bonus, missions, loyalty, referrals, sportsbook and bets namespaces |
49
50
  | `@getenginex/sdk-igaming/testing` | Mock routes for iGaming (`withIgamingRoutes`) on top of the core's `createMockFetch` |
50
51
  | `@getenginex/sdk-igaming/first-frame` | Origin-checked `postMessage` events and commands for the FIRST sportsbook iframe |
51
52
  | `@getenginex/sdk-igaming/query` | Query and mutation factories for TanStack Query v5 |
@@ -0,0 +1,620 @@
1
+ import { isEnginexError } from '@getenginex/sdk';
2
+ import { moneyText, currencyCode, strictValue, isAmbiguousFailure, lazy, wire, decimalPlaces, mapOf } from '@getenginex/sdk/extension';
3
+ import * as z3 from 'zod/mini';
4
+
5
+ // src/internal/input.ts
6
+ function rejectInput(transport, message, route) {
7
+ return Promise.reject(
8
+ transport.reportError({ code: "CONFIGURATION_ERROR", message, status: 0 }, { ...route, attempt: 0 })
9
+ );
10
+ }
11
+ function pageInputProblem(name, input) {
12
+ if (input === void 0) return void 0;
13
+ if (typeof input !== "object" || input === null || Array.isArray(input)) return `${name}: input must be an object.`;
14
+ const { page, perPage } = input;
15
+ if (page !== void 0 && (typeof page !== "number" || !Number.isSafeInteger(page) || page < 1))
16
+ return `${name}: page must be an integer \u2265 1.`;
17
+ if (perPage !== void 0 && (typeof perPage !== "number" || !Number.isInteger(perPage) || perPage < 1 || perPage > 100))
18
+ return `${name}: perPage must be an integer from 1 to 100.`;
19
+ return void 0;
20
+ }
21
+ var LOCALE = /* @__PURE__ */ Symbol.for("@getenginex/sdk-igaming/locale");
22
+ function optionalTimestamp() {
23
+ return z3.pipe(
24
+ z3.nullish(z3.string().check(z3.refine((value) => value === "" || !Number.isNaN(Date.parse(value)), "invalid date"))),
25
+ z3.transform((value) => value == null || value === "" || Date.parse(value) === 0 ? null : value)
26
+ );
27
+ }
28
+ function optionalText() {
29
+ return z3.pipe(
30
+ z3.nullish(z3.string()),
31
+ z3.transform((value) => value == null || value === "" ? null : value)
32
+ );
33
+ }
34
+ function nullableList(item) {
35
+ return z3.pipe(
36
+ z3.nullish(z3.array(item)),
37
+ z3.transform((value) => value ?? [])
38
+ );
39
+ }
40
+ function protoEnum(prefix) {
41
+ return z3.pipe(
42
+ z3.optional(z3.union([z3.string(), z3.number()])),
43
+ z3.transform((value) => {
44
+ if (value === void 0 || value === 0) return "unspecified";
45
+ if (typeof value === "number") return String(value);
46
+ return (value.startsWith(prefix) ? value.slice(prefix.length) : value).toLowerCase();
47
+ })
48
+ );
49
+ }
50
+ function minorUnits() {
51
+ return moneyText();
52
+ }
53
+ function currencyOrEmpty() {
54
+ return currencyCode({ allowEmpty: true });
55
+ }
56
+ var NON_NEGATIVE_MONEY = "Expected money in minor units: a non-negative integer within the safe range of number";
57
+ function nonNegativeMinorUnits() {
58
+ return z3.pipe(
59
+ strictValue(
60
+ (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0 || typeof v === "string" && /^\d+$/.test(v) && Number.isSafeInteger(Number(v)),
61
+ NON_NEGATIVE_MONEY
62
+ ),
63
+ // `|| 0`: a JSON `-0` comes out as `0`.
64
+ z3.transform((v) => Number(v) || 0)
65
+ );
66
+ }
67
+ var INTEGER_TEXT = "Expected an integer within the safe range of number";
68
+ function integerText() {
69
+ return z3.pipe(
70
+ z3.union([
71
+ z3.string().check(
72
+ z3.refine((value) => /^-?\d+$/.test(value) && Number.isSafeInteger(Number(value)), { message: INTEGER_TEXT })
73
+ ),
74
+ z3.number().check(z3.refine((value) => Number.isSafeInteger(value), { message: INTEGER_TEXT }))
75
+ ]),
76
+ z3.transform(Number)
77
+ );
78
+ }
79
+ function text() {
80
+ return z3._default(z3.string(), "");
81
+ }
82
+ function count() {
83
+ return z3._default(z3.number(), 0);
84
+ }
85
+ function list(item) {
86
+ return nullableList(item);
87
+ }
88
+ function durationSeconds() {
89
+ return z3.pipe(
90
+ z3.string().check(z3.regex(/^-?\d+(\.\d+)?s$/, { message: 'Expected a protobuf duration, e.g. "86400s"' })),
91
+ z3.transform((value) => Number(value.slice(0, -1)))
92
+ );
93
+ }
94
+
95
+ // src/modules/club.ts
96
+ function keepsClubIdempotencyKey(error) {
97
+ if (!isEnginexError(error)) return false;
98
+ if (isAmbiguousFailure(error)) return true;
99
+ return error.status >= 400 && !DEFINITIVE_CLUB_STATUS.has(error.status);
100
+ }
101
+ var DEFINITIVE_CLUB_STATUS = /* @__PURE__ */ new Set([400, 403, 404, 422]);
102
+ var ISO_DATE_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/;
103
+ var ISO_DAY = /^\d{4}-\d{2}-\d{2}$/;
104
+ var DECIMAL = /^(?:0|[1-9]\d{0,19})(?:\.\d{1,20})?$/;
105
+ var EXTERNAL_EDITION = /^ext_[A-Za-z0-9_-]+$/;
106
+ var GO_ZERO_TIME = /^0001-01-01T00:00:00(?:\.0+)?(?:Z|[+-]00:00)$/;
107
+ var time = () => z3.pipe(
108
+ z3.nullish(
109
+ z3.string().check(
110
+ z3.refine(
111
+ (value) => value === "" || ISO_DATE_TIME.test(value) && !Number.isNaN(Date.parse(value)),
112
+ "Expected an ISO 8601 date-time"
113
+ )
114
+ )
115
+ ),
116
+ z3.transform(
117
+ (value) => value == null || value === "" || Date.parse(value) === 0 || GO_ZERO_TIME.test(value) ? null : value
118
+ )
119
+ );
120
+ var flag = () => z3._default(z3.boolean(), false);
121
+ var textOrEmpty = () => z3._default(z3.string(), "");
122
+ var id = () => z3.string().check(z3.minLength(1, "Expected a non-empty id"));
123
+ var localized = () => mapOf(z3.string());
124
+ var units = () => z3._default(integerText(), 0);
125
+ var int32 = () => z3._default(z3.number().check(z3.refine((value) => Number.isSafeInteger(value), "Expected an integer")), 0);
126
+ var rank = () => z3.number().check(z3.refine((value) => Number.isSafeInteger(value) && value >= 1, "Expected an integer \u2265 1"));
127
+ var code = () => z3.pipe(
128
+ protoEnum(""),
129
+ z3.transform((value) => value === "" ? "unspecified" : value)
130
+ );
131
+ var optionalCode = () => z3.pipe(
132
+ z3.nullish(z3.string()),
133
+ z3.transform((value) => value ? value.toLowerCase() : null)
134
+ );
135
+ var nullable = (schema) => z3.pipe(
136
+ z3.nullish(schema),
137
+ z3.transform((value) => value ?? null)
138
+ );
139
+ function uniqueList(item, key) {
140
+ return z3.pipe(
141
+ nullableList(item),
142
+ z3.transform((items) => {
143
+ const seen = /* @__PURE__ */ new Set();
144
+ return items.filter((value) => {
145
+ const k = typeof value === "object" && value !== null ? safeKey(() => key(value)) : String(value);
146
+ if (k === void 0 || seen.has(k)) return false;
147
+ seen.add(k);
148
+ return true;
149
+ });
150
+ })
151
+ );
152
+ }
153
+ function safeKey(read) {
154
+ try {
155
+ const value = read();
156
+ return typeof value === "string" && value !== "" ? value : void 0;
157
+ } catch {
158
+ return void 0;
159
+ }
160
+ }
161
+ var moneySchema = /* @__PURE__ */ lazy(
162
+ () => z3.pipe(
163
+ wire({
164
+ currency: currencyCode(),
165
+ amountMinor: nonNegativeMinorUnits(),
166
+ decimalPlaces: z3.optional(decimalPlaces())
167
+ }),
168
+ z3.transform(
169
+ (m) => ({ amount: m.amountMinor, currency: m.currency, decimalPlaces: m.decimalPlaces ?? null })
170
+ )
171
+ )
172
+ );
173
+ var alternateSchema = /* @__PURE__ */ lazy(
174
+ () => wire({ kind: code(), label: localized(), quantity: units() })
175
+ );
176
+ var rewardSchema = /* @__PURE__ */ lazy(
177
+ () => wire({
178
+ id: textOrEmpty(),
179
+ label: localized(),
180
+ kind: code(),
181
+ quantity: units(),
182
+ money: nullable(moneySchema()),
183
+ campaign: nullable(wire({ spins: units(), gameId: optionalText() })),
184
+ cashback: nullable(
185
+ wire({
186
+ percentageBps: int32(),
187
+ period: optionalCode(),
188
+ basis: optionalCode(),
189
+ destination: optionalCode(),
190
+ startsAt: time(),
191
+ endsAt: time(),
192
+ gameIds: uniqueList(z3.string(), String),
193
+ zeroBasisAlternate: nullable(alternateSchema()),
194
+ priorAwardAlternate: nullable(alternateSchema())
195
+ })
196
+ ),
197
+ manual: nullable(wire({ deliveryType: optionalCode(), instructions: localized() })),
198
+ ttlSeconds: units(),
199
+ editionId: optionalText(),
200
+ ticketOwnedAlternate: nullable(alternateSchema())
201
+ })
202
+ );
203
+ var receiptSchema = /* @__PURE__ */ lazy(
204
+ () => wire({
205
+ id: id(),
206
+ status: code(),
207
+ sourceKind: code(),
208
+ sourceId: optionalText(),
209
+ sliceId: optionalText(),
210
+ reward: nullable(rewardSchema()),
211
+ settlement: nullable(moneySchema()),
212
+ costCoins: units(),
213
+ acceptedAt: time(),
214
+ deliveredAt: time(),
215
+ expiresAt: time(),
216
+ tournamentRank: nullable(rank()),
217
+ ticketConsumed: flag()
218
+ })
219
+ );
220
+ var levelSchema = () => wire({ id: id(), name: localized(), minXp: units(), benefit: localized() });
221
+ var programSchema = /* @__PURE__ */ lazy(
222
+ () => wire({
223
+ enabled: flag(),
224
+ joined: flag(),
225
+ membershipRequired: flag(),
226
+ canJoin: flag(),
227
+ historyAvailable: flag(),
228
+ versionId: optionalText(),
229
+ locale: optionalText(),
230
+ termsLocale: optionalText(),
231
+ timeZone: optionalText(),
232
+ currency: z3.pipe(
233
+ z3._default(currencyOrEmpty(), ""),
234
+ z3.transform((value) => value || null)
235
+ ),
236
+ name: localized(),
237
+ terms: localized(),
238
+ coinName: localized(),
239
+ coverUrl: optionalText(),
240
+ levels: uniqueList(levelSchema(), (level) => level.id)
241
+ })
242
+ );
243
+ var activitySchema = () => wire({
244
+ activity: wire({
245
+ id: id(),
246
+ kind: code(),
247
+ name: localized(),
248
+ terms: localized(),
249
+ coverUrl: optionalText(),
250
+ wheelTheme: optionalCode(),
251
+ playLabel: localized(),
252
+ slices: uniqueList(wire({ id: id(), reward: nullable(rewardSchema()) }), (slice) => slice.id)
253
+ }),
254
+ canPlay: flag(),
255
+ unavailableReason: optionalCode(),
256
+ latestReceipt: nullable(receiptSchema()),
257
+ availableAt: time()
258
+ });
259
+ var missionSchema = () => wire({
260
+ mission: wire({
261
+ id: id(),
262
+ title: localized(),
263
+ terms: localized(),
264
+ recurrence: code(),
265
+ countBy: code(),
266
+ target: units(),
267
+ coverUrl: optionalText()
268
+ }),
269
+ editionId: optionalText(),
270
+ progress: units(),
271
+ rightId: optionalText(),
272
+ rightVersionId: optionalText(),
273
+ chestOptions: nullableList(rewardSchema()),
274
+ canClaim: flag(),
275
+ receipt: nullable(receiptSchema()),
276
+ endsAt: time(),
277
+ claimExpiresAt: time(),
278
+ stampedDays: uniqueList(
279
+ z3.string().check(
280
+ z3.refine((value) => ISO_DAY.test(value) && !Number.isNaN(Date.parse(value)), "Expected a YYYY-MM-DD day")
281
+ ),
282
+ String
283
+ )
284
+ });
285
+ var storeItemSchema = () => wire({
286
+ item: wire({
287
+ id: id(),
288
+ label: localized(),
289
+ terms: localized(),
290
+ costCoins: units(),
291
+ reward: nullable(rewardSchema()),
292
+ coverUrl: optionalText()
293
+ }),
294
+ canRedeem: flag(),
295
+ unavailableReason: optionalCode()
296
+ });
297
+ var rewardsSchema = /* @__PURE__ */ lazy(
298
+ () => wire({
299
+ xp: units(),
300
+ coins: units(),
301
+ levelId: optionalText(),
302
+ activities: uniqueList(activitySchema(), (state) => state.activity.id),
303
+ // The same mission may hold several rights (one per period): a repeat is the same mission, right and period.
304
+ missions: uniqueList(
305
+ missionSchema(),
306
+ (state) => typeof state.mission.id === "string" ? JSON.stringify([state.mission.id, state.rightId ?? state.editionId, state.endsAt]) : void 0
307
+ ),
308
+ storeItems: uniqueList(storeItemSchema(), (state) => state.item.id)
309
+ })
310
+ );
311
+ var overviewSchema = /* @__PURE__ */ lazy(
312
+ () => wire({ program: programSchema(), rewards: nullable(rewardsSchema()) })
313
+ );
314
+ var nextCursor = () => z3.pipe(
315
+ optionalText(),
316
+ z3.transform((value) => value ?? void 0)
317
+ );
318
+ function compactCursor(page) {
319
+ if (page.nextCursor === void 0) delete page.nextCursor;
320
+ return page;
321
+ }
322
+ var historySchema = /* @__PURE__ */ lazy(
323
+ () => z3.pipe(
324
+ wire({
325
+ receipts: uniqueList(receiptSchema(), (receipt) => receipt.id),
326
+ movements: uniqueList(
327
+ wire({ id: id(), kind: code(), units: units(), sourceId: optionalText(), occurredAt: time() }),
328
+ (movement) => movement.id
329
+ ),
330
+ nextCursor: nextCursor()
331
+ }),
332
+ z3.transform(compactCursor)
333
+ )
334
+ );
335
+ var registrationSchema = /* @__PURE__ */ lazy(
336
+ () => wire({ id: id(), editionId: id(), versionId: optionalText(), joinedAt: time() })
337
+ );
338
+ var isMinorUnits = (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0 || typeof v === "string" && /^\d+$/.test(v) && Number.isSafeInteger(Number(v));
339
+ var announcedMoney = () => z3.pipe(
340
+ wire({
341
+ currency: z3.string().check(z3.regex(/^[A-Z]{3}$/, "Expected a currency code, e.g. BRL")),
342
+ amountMinor: z3.union([z3.string(), z3.number()]).check(z3.refine(isMinorUnits, "Expected non-negative minor units")),
343
+ decimalPlaces: z3.optional(
344
+ z3.number().check(z3.refine((v) => Number.isInteger(v) && v >= 0 && v <= 8, "Expected decimal places 0 to 8"))
345
+ )
346
+ }),
347
+ // In `'warn'` the amount may come in raw: only an exact non-negative integer becomes `amount`; anything else stays
348
+ // as it came, so `hasValidAnnouncedAmount` drops the prize (never `Number('1e3')`, never a rounded value).
349
+ z3.transform(
350
+ (m) => ({
351
+ amount: isMinorUnits(m.amountMinor) ? Number(m.amountMinor) || 0 : m.amountMinor,
352
+ currency: m.currency,
353
+ decimalPlaces: m.decimalPlaces ?? null
354
+ })
355
+ )
356
+ );
357
+ var prizeSchema = () => wire({
358
+ fromRank: int32(),
359
+ toRank: int32(),
360
+ reward: nullable(rewardSchema()),
361
+ announcedAmount: nullable(announcedMoney()),
362
+ terms: localized(),
363
+ offerTerms: nullable(
364
+ wire({
365
+ spinDenomination: nullable(moneySchema()),
366
+ wageringMultiplier: nullable(z3.string().check(z3.regex(DECIMAL, "Expected an exact decimal"))),
367
+ validForSeconds: nullable(integerText()),
368
+ expiresAt: time(),
369
+ grantEndsAt: time()
370
+ })
371
+ )
372
+ });
373
+ function hasValidAnnouncedAmount(prize) {
374
+ const amount = prize.announcedAmount;
375
+ if (amount === null) return true;
376
+ if (typeof amount !== "object") return false;
377
+ const { amount: value, currency } = amount;
378
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 && typeof currency === "string" && /^[A-Z]{3}$/.test(currency);
379
+ }
380
+ var tournamentSchema = /* @__PURE__ */ lazy(
381
+ () => wire({
382
+ id: id(),
383
+ source: code(),
384
+ versionId: optionalText(),
385
+ title: localized(),
386
+ terms: localized(),
387
+ status: code(),
388
+ startsAt: time(),
389
+ endsAt: time(),
390
+ updatedAt: time(),
391
+ scoringRule: optionalCode(),
392
+ tieBreak: optionalCode(),
393
+ currency: z3.pipe(
394
+ z3._default(currencyOrEmpty(), ""),
395
+ z3.transform((value) => value || null)
396
+ ),
397
+ timeZone: optionalText(),
398
+ gameIds: uniqueList(z3.string(), String),
399
+ // An announced amount (an external listing) is display data, not a prize the player wins: one outside the
400
+ // format (negative, a fraction, ≥ 2^53, a bad currency) fails without the strict mark, so `'warn'` reports it
401
+ // and drops that prize instead of failing the whole page. Strict mode still rejects it.
402
+ prizes: z3.pipe(
403
+ nullableList(prizeSchema()),
404
+ z3.transform((prizes) => prizes.filter(hasValidAnnouncedAmount))
405
+ ),
406
+ joinMode: optionalCode(),
407
+ locale: optionalText(),
408
+ rankingAvailable: flag(),
409
+ canRegister: flag(),
410
+ requiresTicket: flag(),
411
+ registration: nullable(registrationSchema()),
412
+ personalAward: nullable(receiptSchema()),
413
+ stale: flag(),
414
+ registrationStartsAt: time(),
415
+ registrationEndsAt: time(),
416
+ coverUrl: optionalText()
417
+ })
418
+ );
419
+ var tournamentPageSchema = /* @__PURE__ */ lazy(
420
+ () => z3.pipe(
421
+ wire({
422
+ items: uniqueList(tournamentSchema(), (tournament) => tournament.id),
423
+ externalAvailable: flag(),
424
+ externalStale: flag(),
425
+ nextCursor: nextCursor()
426
+ }),
427
+ z3.transform(compactCursor)
428
+ )
429
+ );
430
+ var relatedPageSchema = /* @__PURE__ */ lazy(
431
+ () => wire({
432
+ relatedTo: textOrEmpty(),
433
+ items: uniqueList(
434
+ wire({
435
+ id: z3.string().check(z3.regex(EXTERNAL_EDITION, "Expected an external edition id")),
436
+ title: localized(),
437
+ status: code(),
438
+ startsAt: time(),
439
+ endsAt: time()
440
+ }),
441
+ (item) => item.id
442
+ ),
443
+ nextCursor: nextCursor()
444
+ })
445
+ );
446
+ var rankSchema = () => wire({ position: rank(), displayName: textOrEmpty(), score: textOrEmpty() });
447
+ var rankingSchema = /* @__PURE__ */ lazy(
448
+ () => wire({ entries: nullableList(rankSchema()), personal: nullable(rankSchema()), updatedAt: time(), final: flag() })
449
+ );
450
+ var playSchema = /* @__PURE__ */ lazy(
451
+ () => wire({ receipt: receiptSchema(), sliceId: optionalText(), rewards: nullable(rewardsSchema()) })
452
+ );
453
+ var BASE = "/casino/club";
454
+ var MAX_ID = 128;
455
+ var MAX_IDEMPOTENCY_KEY = 128;
456
+ var ROUTES = {
457
+ overview: { method: "GET", path: BASE },
458
+ history: { method: "GET", path: `${BASE}/history` },
459
+ tournaments: { method: "GET", path: `${BASE}/tournaments` },
460
+ tournament: { method: "GET", path: `${BASE}/tournaments/{editionId}` },
461
+ ranking: { method: "GET", path: `${BASE}/tournaments/{editionId}/ranking` },
462
+ membership: { method: "PUT", path: `${BASE}/membership` },
463
+ play: { method: "POST", path: `${BASE}/activities/{activityId}/plays` },
464
+ redeem: { method: "POST", path: `${BASE}/rewards/{rewardId}/redemptions` },
465
+ register: { method: "POST", path: `${BASE}/tournaments/{editionId}/registrations` }
466
+ };
467
+ var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
468
+ function utf8Length(value) {
469
+ return new TextEncoder().encode(value).length;
470
+ }
471
+ function idProblem(name, field, value) {
472
+ return typeof value === "string" && value.trim() !== "" && utf8Length(value) <= MAX_ID ? void 0 : `${name}: ${field} must be non-empty text up to ${MAX_ID} UTF-8 bytes.`;
473
+ }
474
+ function optionalTextProblem(name, field, value) {
475
+ return value === void 0 || typeof value === "string" ? void 0 : `${name}: ${field} must be text.`;
476
+ }
477
+ function limitProblem(name, value) {
478
+ return value === void 0 || typeof value === "number" && Number.isInteger(value) && value >= 1 && value <= 100 ? void 0 : `${name}: limit must be an integer from 1 to 100.`;
479
+ }
480
+ function cursorProblem(name, input) {
481
+ if (input === void 0) return void 0;
482
+ if (!isObject(input)) return `${name}: input must be an object.`;
483
+ return optionalTextProblem(name, "cursor", input.cursor) ?? limitProblem(name, input.limit);
484
+ }
485
+ function keyProblem(name, options) {
486
+ const key = options?.idempotencyKey;
487
+ if (key === void 0 || key === "") return void 0;
488
+ return typeof key === "string" && key === key.trim() && /^[\x20-\x7E]+$/.test(key) && key.length <= MAX_IDEMPOTENCY_KEY ? void 0 : `${name}: idempotencyKey must be printable ASCII without surrounding spaces, up to ${MAX_IDEMPOTENCY_KEY} characters.`;
489
+ }
490
+ function membershipProblem(input) {
491
+ const name = "club.setMembership";
492
+ if (!isObject(input)) return `${name}: input must be { versionId, joined, termsLocale? }.`;
493
+ if (typeof input.joined !== "boolean") return `${name}: joined must be true or false.`;
494
+ const versionProblem = idProblem(name, "versionId", input.versionId);
495
+ if (versionProblem) return versionProblem;
496
+ if (input.joined && (typeof input.termsLocale !== "string" || input.termsLocale.trim() === ""))
497
+ return `${name}: termsLocale must be non-empty text when joining.`;
498
+ return void 0;
499
+ }
500
+ var segment = (value) => encodeURIComponent(value);
501
+ function requireObject(transport, route, field) {
502
+ return (value) => {
503
+ if (isObject(value[field])) return value;
504
+ throw transport.reportError(
505
+ {
506
+ code: "VALIDATION_ERROR",
507
+ message: `Unexpected gateway response on ${route.method} ${route.path}: ${field}`,
508
+ status: 200
509
+ },
510
+ route
511
+ );
512
+ };
513
+ }
514
+ function createClubApi(transport) {
515
+ const get = (path, query, schema, options) => transport.request({ method: "GET", path, query, auth: "required", schema, options });
516
+ const write = (method, path, body, schema, options) => (
517
+ // The key goes only in the `Idempotency-Key` header: the gateway reads it from there when the body has none
518
+ // (a body key that differed from the header would be refused).
519
+ transport.request({ method, path, body, auth: "required", idempotent: true, schema, options })
520
+ );
521
+ return {
522
+ getOverview: (_params, options) => get(BASE, {}, overviewSchema(), options).then(requireObject(transport, ROUTES.overview, "program")),
523
+ listHistory: (input, options) => {
524
+ const problem = cursorProblem("club.listHistory", input);
525
+ if (problem !== void 0) return rejectInput(transport, problem, ROUTES.history);
526
+ return get(
527
+ ROUTES.history.path,
528
+ { cursor: input?.cursor || void 0, limit: input?.limit },
529
+ historySchema(),
530
+ options
531
+ );
532
+ },
533
+ listTournaments: (input, options) => {
534
+ const problem = cursorProblem("club.listTournaments", input);
535
+ if (problem !== void 0) return rejectInput(transport, problem, ROUTES.tournaments);
536
+ return get(
537
+ ROUTES.tournaments.path,
538
+ { cursor: input?.cursor || void 0, limit: input?.limit },
539
+ tournamentPageSchema(),
540
+ options
541
+ );
542
+ },
543
+ listRelatedTournaments: (input, options) => {
544
+ const name = "club.listRelatedTournaments";
545
+ const problem = !isObject(input) ? `${name}: input must be { editionId }.` : typeof input.editionId !== "string" || utf8Length(input.editionId) > MAX_ID || !EXTERNAL_EDITION.test(input.editionId) ? `${name}: editionId must be an external edition id (ext_...), up to ${MAX_ID} characters.` : cursorProblem(name, input);
546
+ if (problem !== void 0) return rejectInput(transport, problem, ROUTES.tournaments);
547
+ return get(
548
+ ROUTES.tournaments.path,
549
+ { relatedTo: input.editionId, cursor: input.cursor || void 0, limit: input.limit },
550
+ relatedPageSchema(),
551
+ options
552
+ ).then(({ relatedTo, items, nextCursor: cursor }) => {
553
+ if (relatedTo !== input.editionId) return { items: [] };
554
+ return cursor === void 0 ? { items } : { items, nextCursor: cursor };
555
+ });
556
+ },
557
+ getTournament: (input, options) => {
558
+ const problem = idProblem("club.getTournament", "editionId", isObject(input) ? input.editionId : void 0);
559
+ if (problem !== void 0) return rejectInput(transport, problem, ROUTES.tournament);
560
+ return get(`${BASE}/tournaments/${segment(input.editionId)}`, {}, tournamentSchema(), options);
561
+ },
562
+ getRanking: (input, options) => {
563
+ const name = "club.getRanking";
564
+ const problem = isObject(input) ? idProblem(name, "editionId", input.editionId) ?? limitProblem(name, input.limit) : `${name}: input must be { editionId }.`;
565
+ if (problem !== void 0) return rejectInput(transport, problem, ROUTES.ranking);
566
+ return get(
567
+ `${BASE}/tournaments/${segment(input.editionId)}/ranking`,
568
+ { limit: input.limit },
569
+ rankingSchema(),
570
+ options
571
+ );
572
+ },
573
+ setMembership: (input, options) => {
574
+ const problem = membershipProblem(input) ?? keyProblem("club.setMembership", options);
575
+ if (problem !== void 0) return rejectInput(transport, problem, ROUTES.membership);
576
+ const body = input.joined ? { versionId: input.versionId, joined: true, termsLocale: input.termsLocale } : { versionId: input.versionId, joined: false };
577
+ return write("PUT", ROUTES.membership.path, body, programSchema(), options);
578
+ },
579
+ play: (input, options) => {
580
+ const name = "club.play";
581
+ const problem = isObject(input) ? idProblem(name, "activityId", input.activityId) ?? idProblem(name, "versionId", input.versionId) ?? optionalTextProblem(name, "optionId", input.optionId) ?? keyProblem(name, options) : `${name}: input must be { activityId, versionId, optionId? }.`;
582
+ if (problem !== void 0) return rejectInput(transport, problem, ROUTES.play);
583
+ const body = { versionId: input.versionId };
584
+ if (input.optionId) body.optionId = input.optionId;
585
+ return write("POST", `${BASE}/activities/${segment(input.activityId)}/plays`, body, playSchema(), options).then(
586
+ requireObject(transport, ROUTES.play, "receipt")
587
+ );
588
+ },
589
+ redeem: (input, options) => {
590
+ const name = "club.redeem";
591
+ const problem = isObject(input) ? idProblem(name, "rewardId", input.rewardId) ?? idProblem(name, "versionId", input.versionId) ?? keyProblem(name, options) : `${name}: input must be { rewardId, versionId }.`;
592
+ if (problem !== void 0) return rejectInput(transport, problem, ROUTES.redeem);
593
+ return write(
594
+ "POST",
595
+ `${BASE}/rewards/${segment(input.rewardId)}/redemptions`,
596
+ { versionId: input.versionId },
597
+ receiptSchema(),
598
+ options
599
+ );
600
+ },
601
+ registerForTournament: (input, options) => {
602
+ const name = "club.registerForTournament";
603
+ const problem = isObject(input) ? idProblem(name, "editionId", input.editionId) ?? idProblem(name, "versionId", input.versionId) ?? optionalTextProblem(name, "ticketId", input.ticketId) ?? keyProblem(name, options) : `${name}: input must be { editionId, versionId, ticketId? }.`;
604
+ if (problem !== void 0) return rejectInput(transport, problem, ROUTES.register);
605
+ const body = { versionId: input.versionId };
606
+ if (input.ticketId) body.ticketId = input.ticketId;
607
+ return write(
608
+ "POST",
609
+ `${BASE}/tournaments/${segment(input.editionId)}/registrations`,
610
+ body,
611
+ registrationSchema(),
612
+ options
613
+ );
614
+ }
615
+ };
616
+ }
617
+
618
+ export { LOCALE, count, createClubApi, currencyOrEmpty, durationSeconds, integerText, keepsClubIdempotencyKey, list, minorUnits, nonNegativeMinorUnits, nullableList, optionalText, optionalTimestamp, pageInputProblem, protoEnum, rejectInput, text };
619
+ //# sourceMappingURL=chunk-LMBQDSFV.js.map
620
+ //# sourceMappingURL=chunk-LMBQDSFV.js.map