@getenginex/sdk-igaming 0.5.0 → 0.7.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/dist/index.cjs CHANGED
@@ -41,7 +41,7 @@ function minorUnits() {
41
41
  function currencyOrEmpty() {
42
42
  return extension.currencyCode({ allowEmpty: true });
43
43
  }
44
- var INTEGER_TEXT = "Esperava um inteiro dentro da faixa segura do number";
44
+ var INTEGER_TEXT = "Expected an integer within the safe range of number";
45
45
  function integerText() {
46
46
  return mini.z.pipe(
47
47
  mini.z.union([
@@ -64,11 +64,11 @@ function list(item) {
64
64
  }
65
65
  function durationSeconds() {
66
66
  return mini.z.pipe(
67
- mini.z.string().check(mini.z.regex(/^-?\d+(\.\d+)?s$/, { message: 'Esperava uma dura\xE7\xE3o do protobuf, ex.: "86400s"' })),
67
+ mini.z.string().check(mini.z.regex(/^-?\d+(\.\d+)?s$/, { message: 'Expected a protobuf duration, e.g. "86400s"' })),
68
68
  mini.z.transform((value) => Number(value.slice(0, -1)))
69
69
  );
70
70
  }
71
- var MAJOR_UNITS = "Esperava um valor em unidade maior (n\xFAmero finito) que caiba em unidades menores inteiras";
71
+ var MAJOR_UNITS = "Expected a value in major units (a finite number) that fits in whole minor units";
72
72
  function majorToMinorUnits(value) {
73
73
  const minor = Math.sign(value) * Math.round(Math.abs(value) * 100);
74
74
  return minor === 0 ? 0 : minor;
@@ -294,6 +294,39 @@ var offerSchema = /* @__PURE__ */ extension.lazy(
294
294
  content: mini.z.optional(content())
295
295
  })
296
296
  );
297
+ function grantMoney(value, currency) {
298
+ return { amount: value?.amount ?? 0, currency: value?.currency || currency };
299
+ }
300
+ var rewardGrant = () => mini.z.pipe(
301
+ extension.wire({
302
+ state: protoEnum("CAMPAIGN_PLAYER_REWARD_GRANT_STATE_"),
303
+ granted: mini.z.optional(money()),
304
+ balance: mini.z.optional(money()),
305
+ converted: mini.z.optional(money()),
306
+ expires_at: mini.z.optional(mini.z.string()),
307
+ wagering: mini.z.optional(
308
+ extension.wire({ required: mini.z.optional(money()), accumulated: mini.z.optional(money()), completed_at: mini.z.optional(mini.z.string()) })
309
+ )
310
+ }),
311
+ mini.z.transform(({ state, granted, balance, converted, expiresAt, wagering }) => {
312
+ const currency = [granted, balance, converted, wagering?.required, wagering?.accumulated].find((m) => m?.currency)?.currency ?? "";
313
+ const out = {
314
+ state,
315
+ granted: grantMoney(granted, currency),
316
+ balance: grantMoney(balance, currency),
317
+ converted: grantMoney(converted, currency)
318
+ };
319
+ if (expiresAt !== void 0) out.expiresAt = expiresAt;
320
+ if (wagering) {
321
+ out.wagering = {
322
+ required: grantMoney(wagering.required, currency),
323
+ accumulated: grantMoney(wagering.accumulated, currency)
324
+ };
325
+ if (wagering.completedAt !== void 0) out.wagering.completedAt = wagering.completedAt;
326
+ }
327
+ return out;
328
+ })
329
+ );
297
330
  var participationSchema = /* @__PURE__ */ extension.lazy(
298
331
  () => mini.z.pipe(
299
332
  extension.wire({
@@ -302,7 +335,7 @@ var participationSchema = /* @__PURE__ */ extension.lazy(
302
335
  campaign_version_id: text(),
303
336
  reward_key: text(),
304
337
  qualification_snapshot: mini.z.optional(qualification()),
305
- // oneof `state`: só um dos casos vem preenchido.
338
+ // oneof `state`: only one of the cases is filled in.
306
339
  enrolled: mini.z.optional(empty()),
307
340
  qualifying: mini.z.optional(empty()),
308
341
  qualified: mini.z.optional(extension.wire({ qualified_at: mini.z.optional(mini.z.string()) })),
@@ -311,6 +344,7 @@ var participationSchema = /* @__PURE__ */ extension.lazy(
311
344
  reward_failed: mini.z.optional(empty()),
312
345
  expired: mini.z.optional(extension.wire({ expired_at: mini.z.optional(mini.z.string()) })),
313
346
  cancelled: mini.z.optional(empty()),
347
+ reward_grant: mini.z.optional(rewardGrant()),
314
348
  snapshot: mini.z.optional(
315
349
  extension.wire({
316
350
  reward: mini.z.optional(reward()),
@@ -326,7 +360,7 @@ var participationSchema = /* @__PURE__ */ extension.lazy(
326
360
  })
327
361
  )
328
362
  }),
329
- // O oneof vira `status` (+ o timestamp do caso); as chaves do oneof não passam adiante.
363
+ // The oneof becomes `status` (+ the timestamp of the case); the oneof's keys are not passed on.
330
364
  mini.z.transform(
331
365
  ({ enrolled, qualifying, qualified, rewardPending, completed, rewardFailed, expired, cancelled, ...rest }) => {
332
366
  const out = { ...rest, status: "unspecified" };
@@ -362,6 +396,66 @@ function toCursorPage(key, data) {
362
396
  if (data.nextCursor) page.nextCursor = data.nextCursor;
363
397
  return page;
364
398
  }
399
+ var nullableDate = () => mini.z.pipe(
400
+ mini.z.nullish(mini.z.string()),
401
+ mini.z.transform((value) => value ?? void 0)
402
+ );
403
+ function compact(value) {
404
+ return Object.fromEntries(Object.entries(value).filter(([, v]) => v !== void 0));
405
+ }
406
+ var overviewSchema = /* @__PURE__ */ extension.lazy(
407
+ () => mini.z.pipe(
408
+ extension.wire({
409
+ currencies: list(
410
+ mini.z.pipe(
411
+ extension.wire({
412
+ currency: currencyOrEmpty(),
413
+ decimal_places: mini.z.number(),
414
+ restricted_total: minorUnits(),
415
+ expiring_7d: minorUnits(),
416
+ open_positions: mini.z.number(),
417
+ next_expires_at: nullableDate(),
418
+ converted: minorUnits(),
419
+ converted_campaigns: mini.z.number()
420
+ }),
421
+ mini.z.transform(compact)
422
+ )
423
+ ),
424
+ as_of: nullableDate()
425
+ }),
426
+ mini.z.transform(compact)
427
+ )
428
+ );
429
+ var positionsPage = /* @__PURE__ */ extension.lazy(
430
+ () => extension.wire({
431
+ rows: list(
432
+ mini.z.pipe(
433
+ extension.wire({
434
+ position_id: mini.z.string(),
435
+ campaign_id: mini.z.string(),
436
+ currency: currencyOrEmpty(),
437
+ decimal_places: mini.z.number(),
438
+ granted: minorUnits(),
439
+ restricted: minorUnits(),
440
+ converted: minorUnits(),
441
+ required: minorUnits(),
442
+ wagered: minorUnits(),
443
+ remaining: minorUnits(),
444
+ state: mini.z.string(),
445
+ // The gateway answers `null` for an action it does not know; known ones are uppercase (`CONVERT`).
446
+ terminal_action: mini.z.pipe(
447
+ mini.z.nullish(mini.z.string()),
448
+ mini.z.transform((value) => value ? value.toLowerCase() : void 0)
449
+ ),
450
+ expires_at: nullableDate(),
451
+ created_at: nullableDate()
452
+ }),
453
+ mini.z.transform((row) => compact(row))
454
+ )
455
+ ),
456
+ next_cursor: mini.z.optional(mini.z.string())
457
+ })
458
+ );
365
459
  var terms = (acceptance) => acceptance && { locale: acceptance.locale, terms_revision: acceptance.termsRevision };
366
460
  function createBonusApi(transport) {
367
461
  const listPage = (path, key, schema, auth, input, options) => transport.request({
@@ -429,7 +523,26 @@ function createBonusApi(transport) {
429
523
  auth: "required",
430
524
  schema: participationEnvelope(),
431
525
  options
432
- }).then((data) => data.participation)
526
+ }).then((data) => data.participation),
527
+ getOverview: (_params, options) => transport.request({
528
+ method: "GET",
529
+ path: "/bonus/overview",
530
+ auth: "required",
531
+ schema: overviewSchema(),
532
+ options
533
+ }),
534
+ listPositions: (input, options) => transport.request({
535
+ method: "GET",
536
+ path: "/bonus/positions",
537
+ query: { limit: input?.pageSize, cursor: input?.cursor, state: input?.state, currency: input?.currency },
538
+ auth: "required",
539
+ schema: positionsPage(),
540
+ options
541
+ }).then(({ rows, nextCursor }) => {
542
+ const page = { items: rows };
543
+ if (nextCursor) page.nextCursor = nextCursor;
544
+ return page;
545
+ })
433
546
  };
434
547
  }
435
548
  var gameSchema = /* @__PURE__ */ extension.lazy(
@@ -458,7 +571,19 @@ var providersSchema = /* @__PURE__ */ extension.lazy(
458
571
  () => mini.z.array(extension.wire({ id: mini.z.string(), name: mini.z.string(), game_count: mini.z.number() }))
459
572
  );
460
573
  var launchSchema = /* @__PURE__ */ extension.lazy(
461
- () => extension.wire({ session_id: mini.z.string().check(mini.z.minLength(1)), game_url: mini.z.string().check(mini.z.minLength(1)) })
574
+ () => mini.z.pipe(
575
+ extension.wire({
576
+ session_id: mini.z.string().check(mini.z.minLength(1)),
577
+ game_url: mini.z.string().check(mini.z.minLength(1)),
578
+ // Any text: a target the SDK does not know yet must not fail the (strict) launch.
579
+ launch_target: mini.z.optional(mini.z.string()),
580
+ provider_code: mini.z.optional(mini.z.string()),
581
+ expires_at: mini.z.optional(mini.z.string())
582
+ }),
583
+ // Without a target (an older gateway, or a custom mock), the launch keeps the behavior the SDK documented
584
+ // before the field existed: an iframe.
585
+ mini.z.transform(({ launchTarget, ...rest }) => ({ ...rest, launchTarget: launchTarget || "iframe" }))
586
+ )
462
587
  );
463
588
  var sessionSchema = /* @__PURE__ */ extension.lazy(
464
589
  () => extension.wire({
@@ -530,8 +655,8 @@ function createCasinoApi(transport) {
530
655
  path: `/games/${encodeURIComponent(gameId)}/launch`,
531
656
  body: { is_demo: mode === "demo", is_mobile: isMobile === true, return_url: returnUrl, language },
532
657
  auth: "required",
533
- // A resposta traz a URL com o token da sessão de jogo: nunca pela recuperação do modo `warn`
534
- // (que entregaria um campo cru e a resposta ao `onValidationIssue`).
658
+ // The response carries the URL with the game session token: never through `warn` mode's recovery
659
+ // (which would deliver a raw field and the response to `onValidationIssue`).
535
660
  validation: "strict",
536
661
  schema: launchSchema(),
537
662
  options
@@ -575,18 +700,17 @@ function rejectInput(transport, message, route) {
575
700
  }
576
701
  function pageInputProblem(name, input) {
577
702
  if (input === void 0) return void 0;
578
- if (typeof input !== "object" || input === null || Array.isArray(input))
579
- return `${name}: o input precisa ser um objeto.`;
703
+ if (typeof input !== "object" || input === null || Array.isArray(input)) return `${name}: input must be an object.`;
580
704
  const { page, perPage } = input;
581
705
  if (page !== void 0 && (typeof page !== "number" || !Number.isSafeInteger(page) || page < 1))
582
- return `${name}: page precisa ser um inteiro \u2265 1.`;
706
+ return `${name}: page must be an integer \u2265 1.`;
583
707
  if (perPage !== void 0 && (typeof perPage !== "number" || !Number.isInteger(perPage) || perPage < 1 || perPage > 100))
584
- return `${name}: perPage precisa ser um inteiro de 1 a 100.`;
708
+ return `${name}: perPage must be an integer from 1 to 100.`;
585
709
  return void 0;
586
710
  }
587
711
  function optionalTimestamp() {
588
712
  return mini.z.pipe(
589
- mini.z.nullish(mini.z.string().check(mini.z.refine((value) => value === "" || !Number.isNaN(Date.parse(value)), "data inv\xE1lida"))),
713
+ mini.z.nullish(mini.z.string().check(mini.z.refine((value) => value === "" || !Number.isNaN(Date.parse(value)), "invalid date"))),
590
714
  mini.z.transform((value) => value == null || value === "" || Date.parse(value) === 0 ? null : value)
591
715
  );
592
716
  }
@@ -616,7 +740,7 @@ var tierBenefits = () => mini.z.pipe(
616
740
  }
617
741
  if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed))
618
742
  return parsed;
619
- ctx.issues.push({ code: "custom", message: "tier_benefits_json n\xE3o \xE9 um objeto JSON", input: void 0 });
743
+ ctx.issues.push({ code: "custom", message: "tier_benefits_json is not a JSON object", input: void 0 });
620
744
  return mini.z.NEVER;
621
745
  })
622
746
  );
@@ -646,7 +770,7 @@ var redeemSchema = /* @__PURE__ */ extension.lazy(
646
770
  message: mini.z.optional(mini.z.string()),
647
771
  redeemed_points: integerText(),
648
772
  value: mini.z.nullish(minorUnits()),
649
- // Moeda estrita mesmo no `'warn'`; ausente, `null` e `''` continuam virando `null`.
773
+ // Currency strict even in `'warn'`; absent, `null` and `''` still become `null`.
650
774
  currency: mini.z.pipe(
651
775
  mini.z.nullish(currencyOrEmpty()),
652
776
  mini.z.transform((value) => value == null || value === "" ? null : value)
@@ -663,16 +787,16 @@ var redeemSchema = /* @__PURE__ */ extension.lazy(
663
787
  }))
664
788
  )
665
789
  );
666
- var UNCONFIRMED_REDEEM = "loyalty.redeem: o gateway n\xE3o confirmou o resgate.";
790
+ var UNCONFIRMED_REDEEM = "loyalty.redeem: the gateway did not confirm the redemption.";
667
791
  var REDEEM_ROUTE = { method: "POST", path: "/loyalty/redeem" };
668
792
  function redeemInputProblem(input) {
669
793
  if (typeof input !== "object" || input === null || Array.isArray(input))
670
- return "loyalty.redeem: o input precisa ser um objeto { points, redemptionType }.";
794
+ return "loyalty.redeem: input must be an object { points, redemptionType }.";
671
795
  const { points, redemptionType } = input;
672
796
  if (typeof points !== "number" || !Number.isSafeInteger(points) || points <= 0)
673
- return "loyalty.redeem: points precisa ser um inteiro maior que 0.";
797
+ return "loyalty.redeem: points must be an integer greater than 0.";
674
798
  if (typeof redemptionType !== "string" || redemptionType.trim() === "")
675
- return "loyalty.redeem: redemptionType precisa ser um texto n\xE3o vazio.";
799
+ return "loyalty.redeem: redemptionType must be non-empty text.";
676
800
  return void 0;
677
801
  }
678
802
  function createLoyaltyApi(transport) {
@@ -777,7 +901,7 @@ function createMissionsApi(transport) {
777
901
  var STATUSES = ["pending", "qualified", "completed", "expired", "unspecified"];
778
902
  var status = () => mini.z.pipe(protoEnum("REFERRAL_STATUS_"), mini.z.enum(STATUSES));
779
903
  var DEFAULT_PER_PAGE = 20;
780
- var count2 = () => mini.z._default(mini.z.number().check(mini.z.refine((value) => Number.isInteger(value) && value >= 0, "contador inv\xE1lido")), 0);
904
+ var count2 = () => mini.z._default(mini.z.number().check(mini.z.refine((value) => Number.isInteger(value) && value >= 0, "invalid counter")), 0);
781
905
  var HISTORY_PATH = "/referrals/history";
782
906
  var REGISTER_ROUTE = { method: "POST", path: "/referrals/register" };
783
907
  function maskEmail(value) {
@@ -913,9 +1037,9 @@ var registeredSchema = /* @__PURE__ */ extension.lazy(
913
1037
  var positiveInt = (value, fallback) => typeof value === "number" && Number.isSafeInteger(value) && value >= 1 ? value : fallback;
914
1038
  function registerInputProblem(input) {
915
1039
  if (typeof input !== "object" || input === null || Array.isArray(input))
916
- return "referrals.register: o input precisa ser um objeto { code }.";
1040
+ return "referrals.register: input must be an object { code }.";
917
1041
  const { code } = input;
918
- if (typeof code !== "string" || code.trim() === "") return "referrals.register: code precisa ser um texto n\xE3o vazio.";
1042
+ if (typeof code !== "string" || code.trim() === "") return "referrals.register: code must be non-empty text.";
919
1043
  return void 0;
920
1044
  }
921
1045
  function createReferralsApi(transport) {
@@ -964,11 +1088,11 @@ function createReferralsApi(transport) {
964
1088
  }
965
1089
  };
966
1090
  }
967
- var HTTP_URL = "Esperava uma URL absoluta http(s)";
1091
+ var HTTP_URL = "Expected an absolute http(s) URL";
968
1092
  var sessionSchema2 = /* @__PURE__ */ extension.lazy(
969
1093
  () => mini.z.pipe(
970
1094
  extension.wire({
971
- // O token separado só existe no fio: o schema o declara (contrato estrito) e a saída o descarta.
1095
+ // The separate token only exists on the wire: the schema declares it (strict contract) and the output drops it.
972
1096
  operator_token: mini.z.string(),
973
1097
  launch_url: mini.z.string().check(
974
1098
  mini.z.refine(
@@ -985,7 +1109,7 @@ var sessionSchema2 = /* @__PURE__ */ extension.lazy(
985
1109
  ),
986
1110
  expires_in_seconds: mini.z.number().check(mini.z.refine((n) => Number.isFinite(n) && n > 0, { message: "Esperava > 0" }))
987
1111
  }),
988
- // O relógio é lido quando a resposta é interpretada (= momento da resposta).
1112
+ // The clock is read when the response is interpreted (= moment of the response).
989
1113
  mini.z.transform(({ launchUrl, expiresInSeconds }) => ({
990
1114
  launchUrl,
991
1115
  expiresInSeconds,
@@ -999,8 +1123,8 @@ function createSportsbookApi(transport) {
999
1123
  method: "GET",
1000
1124
  path: "/first/session",
1001
1125
  auth: "required",
1002
- // A resposta traz a URL com o token de operador: nunca pela recuperação do modo `warn`
1003
- // (que entregaria um campo cru e a resposta ao `onValidationIssue`).
1126
+ // The response carries the URL with the operator token: never through `warn` mode's recovery
1127
+ // (which would deliver a raw field and the response to `onValidationIssue`).
1004
1128
  validation: "strict",
1005
1129
  schema: sessionSchema2(),
1006
1130
  options
@@ -1023,7 +1147,7 @@ function createIgaming(client) {
1023
1147
  throw new sdk.EnginexError({
1024
1148
  code: "CONFIGURATION_ERROR",
1025
1149
  status: 0,
1026
- message: `createIgaming exige @getenginex/sdk >=0.5.0 <1.0.0 (peer): atualize o core instalado.`
1150
+ message: `createIgaming requires @getenginex/sdk >=0.5.0 <1.0.0 (peer): update the installed core.`
1027
1151
  });
1028
1152
  }
1029
1153
  extension__namespace.registerProductClient(igaming, client);