@getenginex/sdk-igaming 0.10.1 → 0.12.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,648 @@
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 flagOrNull(value) {
41
+ return typeof value === "boolean" ? value : null;
42
+ }
43
+ function protoEnum(prefix) {
44
+ return z3.pipe(
45
+ z3.optional(z3.union([z3.string(), z3.number()])),
46
+ z3.transform((value) => {
47
+ if (value === void 0 || value === 0) return "unspecified";
48
+ if (typeof value === "number") return String(value);
49
+ return (value.startsWith(prefix) ? value.slice(prefix.length) : value).toLowerCase();
50
+ })
51
+ );
52
+ }
53
+ function minorUnits() {
54
+ return moneyText();
55
+ }
56
+ function currencyOrEmpty() {
57
+ return currencyCode({ allowEmpty: true });
58
+ }
59
+ var NON_NEGATIVE_MONEY = "Expected money in minor units: a non-negative integer within the safe range of number";
60
+ function nonNegativeMinorUnits() {
61
+ return z3.pipe(
62
+ strictValue(
63
+ (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0 || typeof v === "string" && /^\d+$/.test(v) && Number.isSafeInteger(Number(v)),
64
+ NON_NEGATIVE_MONEY
65
+ ),
66
+ // `|| 0`: a JSON `-0` comes out as `0`.
67
+ z3.transform((v) => Number(v) || 0)
68
+ );
69
+ }
70
+ var INTEGER_TEXT = "Expected an integer within the safe range of number";
71
+ function integerText() {
72
+ return z3.pipe(
73
+ z3.union([
74
+ z3.string().check(
75
+ z3.refine((value) => /^-?\d+$/.test(value) && Number.isSafeInteger(Number(value)), { message: INTEGER_TEXT })
76
+ ),
77
+ z3.number().check(z3.refine((value) => Number.isSafeInteger(value), { message: INTEGER_TEXT }))
78
+ ]),
79
+ z3.transform(Number)
80
+ );
81
+ }
82
+ var NON_NEGATIVE_INTEGER = "Expected a non-negative integer within the safe range of number";
83
+ function nonNegativeInteger() {
84
+ return z3.pipe(
85
+ z3.union([
86
+ z3.string().check(
87
+ z3.refine((value) => /^(0|[1-9]\d*)$/.test(value) && Number.isSafeInteger(Number(value)), {
88
+ message: NON_NEGATIVE_INTEGER
89
+ })
90
+ ),
91
+ z3.number().check(z3.refine((value) => Number.isSafeInteger(value) && value >= 0, { message: NON_NEGATIVE_INTEGER }))
92
+ ]),
93
+ // `|| 0`: a JSON `-0` comes out as `0`.
94
+ z3.transform((value) => Number(value) || 0)
95
+ );
96
+ }
97
+ var MINOR_UNITS_TEXT = "Expected money in minor units as int64 text: canonical digits within the safe range of number";
98
+ function minorUnitsText() {
99
+ return z3.pipe(
100
+ strictValue(
101
+ (v) => typeof v === "string" && /^(0|[1-9]\d*)$/.test(v) && Number.isSafeInteger(Number(v)),
102
+ MINOR_UNITS_TEXT
103
+ ),
104
+ z3.transform((v) => Number(v))
105
+ );
106
+ }
107
+ function text() {
108
+ return z3._default(z3.string(), "");
109
+ }
110
+ function count() {
111
+ return z3._default(z3.number(), 0);
112
+ }
113
+ function list(item) {
114
+ return nullableList(item);
115
+ }
116
+ function durationSeconds() {
117
+ return z3.pipe(
118
+ z3.string().check(z3.regex(/^-?\d+(\.\d+)?s$/, { message: 'Expected a protobuf duration, e.g. "86400s"' })),
119
+ z3.transform((value) => Number(value.slice(0, -1)))
120
+ );
121
+ }
122
+
123
+ // src/modules/club.ts
124
+ function keepsClubIdempotencyKey(error) {
125
+ if (!isEnginexError(error)) return false;
126
+ if (isAmbiguousFailure(error)) return true;
127
+ return error.status >= 400 && !DEFINITIVE_CLUB_STATUS.has(error.status);
128
+ }
129
+ var DEFINITIVE_CLUB_STATUS = /* @__PURE__ */ new Set([400, 403, 404, 422]);
130
+ 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})$/;
131
+ var ISO_DAY = /^\d{4}-\d{2}-\d{2}$/;
132
+ var DECIMAL = /^(?:0|[1-9]\d{0,19})(?:\.\d{1,20})?$/;
133
+ var EXTERNAL_EDITION = /^ext_[A-Za-z0-9_-]+$/;
134
+ var GO_ZERO_TIME = /^0001-01-01T00:00:00(?:\.0+)?(?:Z|[+-]00:00)$/;
135
+ var time = () => z3.pipe(
136
+ z3.nullish(
137
+ z3.string().check(
138
+ z3.refine(
139
+ (value) => value === "" || ISO_DATE_TIME.test(value) && !Number.isNaN(Date.parse(value)),
140
+ "Expected an ISO 8601 date-time"
141
+ )
142
+ )
143
+ ),
144
+ z3.transform(
145
+ (value) => value == null || value === "" || Date.parse(value) === 0 || GO_ZERO_TIME.test(value) ? null : value
146
+ )
147
+ );
148
+ var flag = () => z3._default(z3.boolean(), false);
149
+ var textOrEmpty = () => z3._default(z3.string(), "");
150
+ var id = () => z3.string().check(z3.minLength(1, "Expected a non-empty id"));
151
+ var localized = () => mapOf(z3.string());
152
+ var units = () => z3._default(integerText(), 0);
153
+ var int32 = () => z3._default(z3.number().check(z3.refine((value) => Number.isSafeInteger(value), "Expected an integer")), 0);
154
+ var rank = () => z3.number().check(z3.refine((value) => Number.isSafeInteger(value) && value >= 1, "Expected an integer \u2265 1"));
155
+ var code = () => z3.pipe(
156
+ protoEnum(""),
157
+ z3.transform((value) => value === "" ? "unspecified" : value)
158
+ );
159
+ var optionalCode = () => z3.pipe(
160
+ z3.nullish(z3.string()),
161
+ z3.transform((value) => value ? value.toLowerCase() : null)
162
+ );
163
+ var nullable = (schema) => z3.pipe(
164
+ z3.nullish(schema),
165
+ z3.transform((value) => value ?? null)
166
+ );
167
+ function uniqueList(item, key) {
168
+ return z3.pipe(
169
+ nullableList(item),
170
+ z3.transform((items) => {
171
+ const seen = /* @__PURE__ */ new Set();
172
+ return items.filter((value) => {
173
+ const k = typeof value === "object" && value !== null ? safeKey(() => key(value)) : String(value);
174
+ if (k === void 0 || seen.has(k)) return false;
175
+ seen.add(k);
176
+ return true;
177
+ });
178
+ })
179
+ );
180
+ }
181
+ function safeKey(read) {
182
+ try {
183
+ const value = read();
184
+ return typeof value === "string" && value !== "" ? value : void 0;
185
+ } catch {
186
+ return void 0;
187
+ }
188
+ }
189
+ var moneySchema = /* @__PURE__ */ lazy(
190
+ () => z3.pipe(
191
+ wire({
192
+ currency: currencyCode(),
193
+ amountMinor: nonNegativeMinorUnits(),
194
+ decimalPlaces: z3.optional(decimalPlaces())
195
+ }),
196
+ z3.transform(
197
+ (m) => ({ amount: m.amountMinor, currency: m.currency, decimalPlaces: m.decimalPlaces ?? null })
198
+ )
199
+ )
200
+ );
201
+ var alternateSchema = /* @__PURE__ */ lazy(
202
+ () => wire({ kind: code(), label: localized(), quantity: units() })
203
+ );
204
+ var rewardSchema = /* @__PURE__ */ lazy(
205
+ () => wire({
206
+ id: textOrEmpty(),
207
+ label: localized(),
208
+ kind: code(),
209
+ quantity: units(),
210
+ money: nullable(moneySchema()),
211
+ campaign: nullable(wire({ spins: units(), gameId: optionalText() })),
212
+ cashback: nullable(
213
+ wire({
214
+ percentageBps: int32(),
215
+ period: optionalCode(),
216
+ basis: optionalCode(),
217
+ destination: optionalCode(),
218
+ startsAt: time(),
219
+ endsAt: time(),
220
+ gameIds: uniqueList(z3.string(), String),
221
+ zeroBasisAlternate: nullable(alternateSchema()),
222
+ priorAwardAlternate: nullable(alternateSchema())
223
+ })
224
+ ),
225
+ manual: nullable(wire({ deliveryType: optionalCode(), instructions: localized() })),
226
+ ttlSeconds: units(),
227
+ editionId: optionalText(),
228
+ ticketOwnedAlternate: nullable(alternateSchema())
229
+ })
230
+ );
231
+ var receiptSchema = /* @__PURE__ */ lazy(
232
+ () => wire({
233
+ id: id(),
234
+ status: code(),
235
+ sourceKind: code(),
236
+ sourceId: optionalText(),
237
+ sliceId: optionalText(),
238
+ reward: nullable(rewardSchema()),
239
+ settlement: nullable(moneySchema()),
240
+ costCoins: units(),
241
+ acceptedAt: time(),
242
+ deliveredAt: time(),
243
+ expiresAt: time(),
244
+ tournamentRank: nullable(rank()),
245
+ ticketConsumed: flag()
246
+ })
247
+ );
248
+ var levelSchema = () => wire({ id: id(), name: localized(), minXp: units(), benefit: localized() });
249
+ var programSchema = /* @__PURE__ */ lazy(
250
+ () => wire({
251
+ enabled: flag(),
252
+ joined: flag(),
253
+ membershipRequired: flag(),
254
+ canJoin: flag(),
255
+ historyAvailable: flag(),
256
+ versionId: optionalText(),
257
+ locale: optionalText(),
258
+ termsLocale: optionalText(),
259
+ timeZone: optionalText(),
260
+ currency: z3.pipe(
261
+ z3._default(currencyOrEmpty(), ""),
262
+ z3.transform((value) => value || null)
263
+ ),
264
+ name: localized(),
265
+ terms: localized(),
266
+ coinName: localized(),
267
+ coverUrl: optionalText(),
268
+ levels: uniqueList(levelSchema(), (level) => level.id)
269
+ })
270
+ );
271
+ var activitySchema = () => wire({
272
+ activity: wire({
273
+ id: id(),
274
+ kind: code(),
275
+ name: localized(),
276
+ terms: localized(),
277
+ coverUrl: optionalText(),
278
+ wheelTheme: optionalCode(),
279
+ playLabel: localized(),
280
+ slices: uniqueList(wire({ id: id(), reward: nullable(rewardSchema()) }), (slice) => slice.id)
281
+ }),
282
+ canPlay: flag(),
283
+ unavailableReason: optionalCode(),
284
+ latestReceipt: nullable(receiptSchema()),
285
+ availableAt: time()
286
+ });
287
+ var missionSchema = () => wire({
288
+ mission: wire({
289
+ id: id(),
290
+ title: localized(),
291
+ terms: localized(),
292
+ recurrence: code(),
293
+ countBy: code(),
294
+ target: units(),
295
+ coverUrl: optionalText()
296
+ }),
297
+ editionId: optionalText(),
298
+ progress: units(),
299
+ rightId: optionalText(),
300
+ rightVersionId: optionalText(),
301
+ chestOptions: nullableList(rewardSchema()),
302
+ canClaim: flag(),
303
+ receipt: nullable(receiptSchema()),
304
+ endsAt: time(),
305
+ claimExpiresAt: time(),
306
+ stampedDays: uniqueList(
307
+ z3.string().check(
308
+ z3.refine((value) => ISO_DAY.test(value) && !Number.isNaN(Date.parse(value)), "Expected a YYYY-MM-DD day")
309
+ ),
310
+ String
311
+ )
312
+ });
313
+ var storeItemSchema = () => wire({
314
+ item: wire({
315
+ id: id(),
316
+ label: localized(),
317
+ terms: localized(),
318
+ costCoins: units(),
319
+ reward: nullable(rewardSchema()),
320
+ coverUrl: optionalText()
321
+ }),
322
+ canRedeem: flag(),
323
+ unavailableReason: optionalCode()
324
+ });
325
+ var rewardsSchema = /* @__PURE__ */ lazy(
326
+ () => wire({
327
+ xp: units(),
328
+ coins: units(),
329
+ levelId: optionalText(),
330
+ activities: uniqueList(activitySchema(), (state) => state.activity.id),
331
+ // The same mission may hold several rights (one per period): a repeat is the same mission, right and period.
332
+ missions: uniqueList(
333
+ missionSchema(),
334
+ (state) => typeof state.mission.id === "string" ? JSON.stringify([state.mission.id, state.rightId ?? state.editionId, state.endsAt]) : void 0
335
+ ),
336
+ storeItems: uniqueList(storeItemSchema(), (state) => state.item.id)
337
+ })
338
+ );
339
+ var overviewSchema = /* @__PURE__ */ lazy(
340
+ () => wire({ program: programSchema(), rewards: nullable(rewardsSchema()) })
341
+ );
342
+ var nextCursor = () => z3.pipe(
343
+ optionalText(),
344
+ z3.transform((value) => value ?? void 0)
345
+ );
346
+ function compactCursor(page) {
347
+ if (page.nextCursor === void 0) delete page.nextCursor;
348
+ return page;
349
+ }
350
+ var historySchema = /* @__PURE__ */ lazy(
351
+ () => z3.pipe(
352
+ wire({
353
+ receipts: uniqueList(receiptSchema(), (receipt) => receipt.id),
354
+ movements: uniqueList(
355
+ wire({ id: id(), kind: code(), units: units(), sourceId: optionalText(), occurredAt: time() }),
356
+ (movement) => movement.id
357
+ ),
358
+ nextCursor: nextCursor()
359
+ }),
360
+ z3.transform(compactCursor)
361
+ )
362
+ );
363
+ var registrationSchema = /* @__PURE__ */ lazy(
364
+ () => wire({ id: id(), editionId: id(), versionId: optionalText(), joinedAt: time() })
365
+ );
366
+ var isMinorUnits = (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0 || typeof v === "string" && /^\d+$/.test(v) && Number.isSafeInteger(Number(v));
367
+ var announcedMoney = () => z3.pipe(
368
+ wire({
369
+ currency: z3.string().check(z3.regex(/^[A-Z]{3}$/, "Expected a currency code, e.g. BRL")),
370
+ amountMinor: z3.union([z3.string(), z3.number()]).check(z3.refine(isMinorUnits, "Expected non-negative minor units")),
371
+ decimalPlaces: z3.optional(
372
+ z3.number().check(z3.refine((v) => Number.isInteger(v) && v >= 0 && v <= 8, "Expected decimal places 0 to 8"))
373
+ )
374
+ }),
375
+ // In `'warn'` the amount may come in raw: only an exact non-negative integer becomes `amount`; anything else stays
376
+ // as it came, so `hasValidAnnouncedAmount` drops the prize (never `Number('1e3')`, never a rounded value).
377
+ z3.transform(
378
+ (m) => ({
379
+ amount: isMinorUnits(m.amountMinor) ? Number(m.amountMinor) || 0 : m.amountMinor,
380
+ currency: m.currency,
381
+ decimalPlaces: m.decimalPlaces ?? null
382
+ })
383
+ )
384
+ );
385
+ var prizeSchema = () => wire({
386
+ fromRank: int32(),
387
+ toRank: int32(),
388
+ reward: nullable(rewardSchema()),
389
+ announcedAmount: nullable(announcedMoney()),
390
+ terms: localized(),
391
+ offerTerms: nullable(
392
+ wire({
393
+ spinDenomination: nullable(moneySchema()),
394
+ wageringMultiplier: nullable(z3.string().check(z3.regex(DECIMAL, "Expected an exact decimal"))),
395
+ validForSeconds: nullable(integerText()),
396
+ expiresAt: time(),
397
+ grantEndsAt: time()
398
+ })
399
+ )
400
+ });
401
+ function hasValidAnnouncedAmount(prize) {
402
+ const amount = prize.announcedAmount;
403
+ if (amount === null) return true;
404
+ if (typeof amount !== "object") return false;
405
+ const { amount: value, currency } = amount;
406
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 && typeof currency === "string" && /^[A-Z]{3}$/.test(currency);
407
+ }
408
+ var tournamentSchema = /* @__PURE__ */ lazy(
409
+ () => wire({
410
+ id: id(),
411
+ source: code(),
412
+ versionId: optionalText(),
413
+ title: localized(),
414
+ terms: localized(),
415
+ status: code(),
416
+ startsAt: time(),
417
+ endsAt: time(),
418
+ updatedAt: time(),
419
+ scoringRule: optionalCode(),
420
+ tieBreak: optionalCode(),
421
+ currency: z3.pipe(
422
+ z3._default(currencyOrEmpty(), ""),
423
+ z3.transform((value) => value || null)
424
+ ),
425
+ timeZone: optionalText(),
426
+ gameIds: uniqueList(z3.string(), String),
427
+ // An announced amount (an external listing) is display data, not a prize the player wins: one outside the
428
+ // format (negative, a fraction, ≥ 2^53, a bad currency) fails without the strict mark, so `'warn'` reports it
429
+ // and drops that prize instead of failing the whole page. Strict mode still rejects it.
430
+ prizes: z3.pipe(
431
+ nullableList(prizeSchema()),
432
+ z3.transform((prizes) => prizes.filter(hasValidAnnouncedAmount))
433
+ ),
434
+ joinMode: optionalCode(),
435
+ locale: optionalText(),
436
+ rankingAvailable: flag(),
437
+ canRegister: flag(),
438
+ requiresTicket: flag(),
439
+ registration: nullable(registrationSchema()),
440
+ personalAward: nullable(receiptSchema()),
441
+ stale: flag(),
442
+ registrationStartsAt: time(),
443
+ registrationEndsAt: time(),
444
+ coverUrl: optionalText()
445
+ })
446
+ );
447
+ var tournamentPageSchema = /* @__PURE__ */ lazy(
448
+ () => z3.pipe(
449
+ wire({
450
+ items: uniqueList(tournamentSchema(), (tournament) => tournament.id),
451
+ externalAvailable: flag(),
452
+ externalStale: flag(),
453
+ nextCursor: nextCursor()
454
+ }),
455
+ z3.transform(compactCursor)
456
+ )
457
+ );
458
+ var relatedPageSchema = /* @__PURE__ */ lazy(
459
+ () => wire({
460
+ relatedTo: textOrEmpty(),
461
+ items: uniqueList(
462
+ wire({
463
+ id: z3.string().check(z3.regex(EXTERNAL_EDITION, "Expected an external edition id")),
464
+ title: localized(),
465
+ status: code(),
466
+ startsAt: time(),
467
+ endsAt: time()
468
+ }),
469
+ (item) => item.id
470
+ ),
471
+ nextCursor: nextCursor()
472
+ })
473
+ );
474
+ var rankSchema = () => wire({ position: rank(), displayName: textOrEmpty(), score: textOrEmpty() });
475
+ var rankingSchema = /* @__PURE__ */ lazy(
476
+ () => wire({ entries: nullableList(rankSchema()), personal: nullable(rankSchema()), updatedAt: time(), final: flag() })
477
+ );
478
+ var playSchema = /* @__PURE__ */ lazy(
479
+ () => wire({ receipt: receiptSchema(), sliceId: optionalText(), rewards: nullable(rewardsSchema()) })
480
+ );
481
+ var BASE = "/casino/club";
482
+ var MAX_ID = 128;
483
+ var MAX_IDEMPOTENCY_KEY = 128;
484
+ var ROUTES = {
485
+ overview: { method: "GET", path: BASE },
486
+ history: { method: "GET", path: `${BASE}/history` },
487
+ tournaments: { method: "GET", path: `${BASE}/tournaments` },
488
+ tournament: { method: "GET", path: `${BASE}/tournaments/{editionId}` },
489
+ ranking: { method: "GET", path: `${BASE}/tournaments/{editionId}/ranking` },
490
+ membership: { method: "PUT", path: `${BASE}/membership` },
491
+ play: { method: "POST", path: `${BASE}/activities/{activityId}/plays` },
492
+ redeem: { method: "POST", path: `${BASE}/rewards/{rewardId}/redemptions` },
493
+ register: { method: "POST", path: `${BASE}/tournaments/{editionId}/registrations` }
494
+ };
495
+ var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
496
+ function utf8Length(value) {
497
+ return new TextEncoder().encode(value).length;
498
+ }
499
+ function idProblem(name, field, value) {
500
+ 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.`;
501
+ }
502
+ function optionalTextProblem(name, field, value) {
503
+ return value === void 0 || typeof value === "string" ? void 0 : `${name}: ${field} must be text.`;
504
+ }
505
+ function limitProblem(name, value) {
506
+ 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.`;
507
+ }
508
+ function cursorProblem(name, input) {
509
+ if (input === void 0) return void 0;
510
+ if (!isObject(input)) return `${name}: input must be an object.`;
511
+ return optionalTextProblem(name, "cursor", input.cursor) ?? limitProblem(name, input.limit);
512
+ }
513
+ function keyProblem(name, options) {
514
+ const key = options?.idempotencyKey;
515
+ if (key === void 0 || key === "") return void 0;
516
+ 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.`;
517
+ }
518
+ function membershipProblem(input) {
519
+ const name = "club.setMembership";
520
+ if (!isObject(input)) return `${name}: input must be { versionId, joined, termsLocale? }.`;
521
+ if (typeof input.joined !== "boolean") return `${name}: joined must be true or false.`;
522
+ const versionProblem = idProblem(name, "versionId", input.versionId);
523
+ if (versionProblem) return versionProblem;
524
+ if (input.joined && (typeof input.termsLocale !== "string" || input.termsLocale.trim() === ""))
525
+ return `${name}: termsLocale must be non-empty text when joining.`;
526
+ return void 0;
527
+ }
528
+ var segment = (value) => encodeURIComponent(value);
529
+ function requireObject(transport, route, field) {
530
+ return (value) => {
531
+ if (isObject(value[field])) return value;
532
+ throw transport.reportError(
533
+ {
534
+ code: "VALIDATION_ERROR",
535
+ message: `Unexpected gateway response on ${route.method} ${route.path}: ${field}`,
536
+ status: 200
537
+ },
538
+ route
539
+ );
540
+ };
541
+ }
542
+ function createClubApi(transport) {
543
+ const get = (path, query, schema, options) => transport.request({ method: "GET", path, query, auth: "required", schema, options });
544
+ const write = (method, path, body, schema, options) => (
545
+ // The key goes only in the `Idempotency-Key` header: the gateway reads it from there when the body has none
546
+ // (a body key that differed from the header would be refused).
547
+ transport.request({ method, path, body, auth: "required", idempotent: true, schema, options })
548
+ );
549
+ return {
550
+ getOverview: (_params, options) => get(BASE, {}, overviewSchema(), options).then(requireObject(transport, ROUTES.overview, "program")),
551
+ listHistory: (input, options) => {
552
+ const problem = cursorProblem("club.listHistory", input);
553
+ if (problem !== void 0) return rejectInput(transport, problem, ROUTES.history);
554
+ return get(
555
+ ROUTES.history.path,
556
+ { cursor: input?.cursor || void 0, limit: input?.limit },
557
+ historySchema(),
558
+ options
559
+ );
560
+ },
561
+ listTournaments: (input, options) => {
562
+ const problem = cursorProblem("club.listTournaments", input);
563
+ if (problem !== void 0) return rejectInput(transport, problem, ROUTES.tournaments);
564
+ return get(
565
+ ROUTES.tournaments.path,
566
+ { cursor: input?.cursor || void 0, limit: input?.limit },
567
+ tournamentPageSchema(),
568
+ options
569
+ );
570
+ },
571
+ listRelatedTournaments: (input, options) => {
572
+ const name = "club.listRelatedTournaments";
573
+ 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);
574
+ if (problem !== void 0) return rejectInput(transport, problem, ROUTES.tournaments);
575
+ return get(
576
+ ROUTES.tournaments.path,
577
+ { relatedTo: input.editionId, cursor: input.cursor || void 0, limit: input.limit },
578
+ relatedPageSchema(),
579
+ options
580
+ ).then(({ relatedTo, items, nextCursor: cursor }) => {
581
+ if (relatedTo !== input.editionId) return { items: [] };
582
+ return cursor === void 0 ? { items } : { items, nextCursor: cursor };
583
+ });
584
+ },
585
+ getTournament: (input, options) => {
586
+ const problem = idProblem("club.getTournament", "editionId", isObject(input) ? input.editionId : void 0);
587
+ if (problem !== void 0) return rejectInput(transport, problem, ROUTES.tournament);
588
+ return get(`${BASE}/tournaments/${segment(input.editionId)}`, {}, tournamentSchema(), options);
589
+ },
590
+ getRanking: (input, options) => {
591
+ const name = "club.getRanking";
592
+ const problem = isObject(input) ? idProblem(name, "editionId", input.editionId) ?? limitProblem(name, input.limit) : `${name}: input must be { editionId }.`;
593
+ if (problem !== void 0) return rejectInput(transport, problem, ROUTES.ranking);
594
+ return get(
595
+ `${BASE}/tournaments/${segment(input.editionId)}/ranking`,
596
+ { limit: input.limit },
597
+ rankingSchema(),
598
+ options
599
+ );
600
+ },
601
+ setMembership: (input, options) => {
602
+ const problem = membershipProblem(input) ?? keyProblem("club.setMembership", options);
603
+ if (problem !== void 0) return rejectInput(transport, problem, ROUTES.membership);
604
+ const body = input.joined ? { versionId: input.versionId, joined: true, termsLocale: input.termsLocale } : { versionId: input.versionId, joined: false };
605
+ return write("PUT", ROUTES.membership.path, body, programSchema(), options);
606
+ },
607
+ play: (input, options) => {
608
+ const name = "club.play";
609
+ 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? }.`;
610
+ if (problem !== void 0) return rejectInput(transport, problem, ROUTES.play);
611
+ const body = { versionId: input.versionId };
612
+ if (input.optionId) body.optionId = input.optionId;
613
+ return write("POST", `${BASE}/activities/${segment(input.activityId)}/plays`, body, playSchema(), options).then(
614
+ requireObject(transport, ROUTES.play, "receipt")
615
+ );
616
+ },
617
+ redeem: (input, options) => {
618
+ const name = "club.redeem";
619
+ const problem = isObject(input) ? idProblem(name, "rewardId", input.rewardId) ?? idProblem(name, "versionId", input.versionId) ?? keyProblem(name, options) : `${name}: input must be { rewardId, versionId }.`;
620
+ if (problem !== void 0) return rejectInput(transport, problem, ROUTES.redeem);
621
+ return write(
622
+ "POST",
623
+ `${BASE}/rewards/${segment(input.rewardId)}/redemptions`,
624
+ { versionId: input.versionId },
625
+ receiptSchema(),
626
+ options
627
+ );
628
+ },
629
+ registerForTournament: (input, options) => {
630
+ const name = "club.registerForTournament";
631
+ 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? }.`;
632
+ if (problem !== void 0) return rejectInput(transport, problem, ROUTES.register);
633
+ const body = { versionId: input.versionId };
634
+ if (input.ticketId) body.ticketId = input.ticketId;
635
+ return write(
636
+ "POST",
637
+ `${BASE}/tournaments/${segment(input.editionId)}/registrations`,
638
+ body,
639
+ registrationSchema(),
640
+ options
641
+ );
642
+ }
643
+ };
644
+ }
645
+
646
+ export { LOCALE, count, createClubApi, currencyOrEmpty, durationSeconds, flagOrNull, integerText, keepsClubIdempotencyKey, list, minorUnits, minorUnitsText, nonNegativeInteger, nonNegativeMinorUnits, nullableList, optionalText, optionalTimestamp, pageInputProblem, protoEnum, rejectInput, text };
647
+ //# sourceMappingURL=chunk-5ERRD3OA.js.map
648
+ //# sourceMappingURL=chunk-5ERRD3OA.js.map