@getenginex/sdk-igaming 0.6.0 → 0.8.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,37 @@
1
1
  # @getenginex/sdk-igaming
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - f1f6b32: `referrals` follows the gateway's current contract (`GET /referrals` and `GET /referrals/history`).
8
+
9
+ **Breaking changes (code changes needed when upgrading):**
10
+
11
+ - `referrals.register` was removed, with `RegisterReferralInput`, `RegisteredReferral` and the `referrals.register` mutation of `createIgamingMutations`: the gateway no longer has `POST /referrals/register`. The code is only entered at sign-up, with the core's `auth.register({ referralCode })`.
12
+ - `referrals.get()` returns `ReferralInfo` `{ enabled, code, rules, totals }`. Gone: `link` (build the invitation link in the app), `totalReferrals`, `completedReferrals`, `pendingReferrals`, `totalEarned`, `bonusPerReferral` and `minDeposit`. `rules` (`ReferralRules`: `reward`, `minimumRealNetLoss`, `refereeWindowDays`, `holdHours`, `wageringMultiplier`, `maximumConversion`) is `null` without an active campaign; `totals` (`ReferralTotals`) counts the referrals per status.
13
+ - `referrals.listHistory()` items are `Referral` `{ id, refereeName, status, createdAt, deadlineAt, progress }`. Gone: `refereeEmailMasked` (the gateway no longer sends the email; `refereeName` arrives already masked by the bonus service), `code`, `referrerBonus`, `refereeBonus`, `completedAt` and `expiresAt`. The page has `code` (the player's referral code) instead of `completedCount` and `totalEarned`.
14
+ - `ReferralStatus` has the bonus service's values: `registered`, `deposited`, `in_hold`, `paid`, `not_eligible`, `expired`, `cancelled` (open union). It is read from `player_status`; against an older gateway that only sends the legacy `status`, `COMPLETED` becomes `paid`, `EXPIRED` `expired` and anything else `registered`.
15
+ - Money is `ReferralMoney` `{ amount, currency }` in minor units, read from the gateway's `{ minor_units, currency }` (integer as text, strict even in `'warn'`), instead of a major-unit float without a currency.
16
+
17
+ **New:** `ReferralProgress` `{ depositDone, realNetLoss, target, remaining }` on each referral (`remaining` computed as `max(0, target - realNetLoss)` when the gateway leaves it out). The `/testing` mock answers the new shapes (an active campaign and three referrals: `paid`, `deposited`, `expired`) and no longer answers `POST /referrals/register`. Docs: the Referrals page and an "iGaming 0.7 to 0.8" section in Upgrading (EN/PT/ES).
18
+
19
+ ## 0.7.0
20
+
21
+ ### Minor Changes
22
+
23
+ - 28a3282: The player's bonus balance and the reward grant of a participation.
24
+
25
+ **New:**
26
+
27
+ - `bonus.getOverview()` (`GET /bonus/overview`): the restricted bonus balance per currency (`BonusOverview`).
28
+ - `bonus.listPositions({ state?, currency?, pageSize?, cursor? })` (`GET /bonus/positions`): bonus positions with their rollover progress, as a `CursorPage<BonusPosition>`; `terminalAction` comes in lowercase.
29
+ - `CampaignParticipation.rewardGrant` (`CampaignRewardGrant`): `state` (`active`, `converted`, `expired`, `forfeited`), `granted`, `balance`, `converted`, `expiresAt` and the `wagering` progress. Amounts protojson leaves out come as `0` in the currency of the grant's other amounts.
30
+ - Queries: `q.bonus.getOverview` and `q.bonus.listPositions`.
31
+ - `/testing`: claiming a reward credits a grant, which shows up in `GET /bonus/overview` and `GET /bonus/positions`.
32
+
33
+ Campaign lists the gateway leaves out (protojson with `EmitUnpopulated` off, e.g. `use_policy.casino` arriving as `{}`) were already delivered as `[]`; this is now covered by tests and documented.
34
+
3
35
  ## 0.6.0
4
36
 
5
37
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -68,20 +68,6 @@ function durationSeconds() {
68
68
  mini.z.transform((value) => Number(value.slice(0, -1)))
69
69
  );
70
70
  }
71
- var MAJOR_UNITS = "Expected a value in major units (a finite number) that fits in whole minor units";
72
- function majorToMinorUnits(value) {
73
- const minor = Math.sign(value) * Math.round(Math.abs(value) * 100);
74
- return minor === 0 ? 0 : minor;
75
- }
76
- function majorUnits() {
77
- return mini.z.pipe(
78
- extension.strictValue(
79
- (value) => typeof value === "number" && Number.isSafeInteger(majorToMinorUnits(value)),
80
- MAJOR_UNITS
81
- ),
82
- mini.z.transform((value) => majorToMinorUnits(value))
83
- );
84
- }
85
71
 
86
72
  // src/modules/bonus.ts
87
73
  var campaignCurrency = () => mini.z._default(currencyOrEmpty(), "");
@@ -294,6 +280,39 @@ var offerSchema = /* @__PURE__ */ extension.lazy(
294
280
  content: mini.z.optional(content())
295
281
  })
296
282
  );
283
+ function grantMoney(value, currency) {
284
+ return { amount: value?.amount ?? 0, currency: value?.currency || currency };
285
+ }
286
+ var rewardGrant = () => mini.z.pipe(
287
+ extension.wire({
288
+ state: protoEnum("CAMPAIGN_PLAYER_REWARD_GRANT_STATE_"),
289
+ granted: mini.z.optional(money()),
290
+ balance: mini.z.optional(money()),
291
+ converted: mini.z.optional(money()),
292
+ expires_at: mini.z.optional(mini.z.string()),
293
+ wagering: mini.z.optional(
294
+ extension.wire({ required: mini.z.optional(money()), accumulated: mini.z.optional(money()), completed_at: mini.z.optional(mini.z.string()) })
295
+ )
296
+ }),
297
+ mini.z.transform(({ state, granted, balance, converted, expiresAt, wagering }) => {
298
+ const currency = [granted, balance, converted, wagering?.required, wagering?.accumulated].find((m) => m?.currency)?.currency ?? "";
299
+ const out = {
300
+ state,
301
+ granted: grantMoney(granted, currency),
302
+ balance: grantMoney(balance, currency),
303
+ converted: grantMoney(converted, currency)
304
+ };
305
+ if (expiresAt !== void 0) out.expiresAt = expiresAt;
306
+ if (wagering) {
307
+ out.wagering = {
308
+ required: grantMoney(wagering.required, currency),
309
+ accumulated: grantMoney(wagering.accumulated, currency)
310
+ };
311
+ if (wagering.completedAt !== void 0) out.wagering.completedAt = wagering.completedAt;
312
+ }
313
+ return out;
314
+ })
315
+ );
297
316
  var participationSchema = /* @__PURE__ */ extension.lazy(
298
317
  () => mini.z.pipe(
299
318
  extension.wire({
@@ -311,6 +330,7 @@ var participationSchema = /* @__PURE__ */ extension.lazy(
311
330
  reward_failed: mini.z.optional(empty()),
312
331
  expired: mini.z.optional(extension.wire({ expired_at: mini.z.optional(mini.z.string()) })),
313
332
  cancelled: mini.z.optional(empty()),
333
+ reward_grant: mini.z.optional(rewardGrant()),
314
334
  snapshot: mini.z.optional(
315
335
  extension.wire({
316
336
  reward: mini.z.optional(reward()),
@@ -362,6 +382,66 @@ function toCursorPage(key, data) {
362
382
  if (data.nextCursor) page.nextCursor = data.nextCursor;
363
383
  return page;
364
384
  }
385
+ var nullableDate = () => mini.z.pipe(
386
+ mini.z.nullish(mini.z.string()),
387
+ mini.z.transform((value) => value ?? void 0)
388
+ );
389
+ function compact(value) {
390
+ return Object.fromEntries(Object.entries(value).filter(([, v]) => v !== void 0));
391
+ }
392
+ var overviewSchema = /* @__PURE__ */ extension.lazy(
393
+ () => mini.z.pipe(
394
+ extension.wire({
395
+ currencies: list(
396
+ mini.z.pipe(
397
+ extension.wire({
398
+ currency: currencyOrEmpty(),
399
+ decimal_places: mini.z.number(),
400
+ restricted_total: minorUnits(),
401
+ expiring_7d: minorUnits(),
402
+ open_positions: mini.z.number(),
403
+ next_expires_at: nullableDate(),
404
+ converted: minorUnits(),
405
+ converted_campaigns: mini.z.number()
406
+ }),
407
+ mini.z.transform(compact)
408
+ )
409
+ ),
410
+ as_of: nullableDate()
411
+ }),
412
+ mini.z.transform(compact)
413
+ )
414
+ );
415
+ var positionsPage = /* @__PURE__ */ extension.lazy(
416
+ () => extension.wire({
417
+ rows: list(
418
+ mini.z.pipe(
419
+ extension.wire({
420
+ position_id: mini.z.string(),
421
+ campaign_id: mini.z.string(),
422
+ currency: currencyOrEmpty(),
423
+ decimal_places: mini.z.number(),
424
+ granted: minorUnits(),
425
+ restricted: minorUnits(),
426
+ converted: minorUnits(),
427
+ required: minorUnits(),
428
+ wagered: minorUnits(),
429
+ remaining: minorUnits(),
430
+ state: mini.z.string(),
431
+ // The gateway answers `null` for an action it does not know; known ones are uppercase (`CONVERT`).
432
+ terminal_action: mini.z.pipe(
433
+ mini.z.nullish(mini.z.string()),
434
+ mini.z.transform((value) => value ? value.toLowerCase() : void 0)
435
+ ),
436
+ expires_at: nullableDate(),
437
+ created_at: nullableDate()
438
+ }),
439
+ mini.z.transform((row) => compact(row))
440
+ )
441
+ ),
442
+ next_cursor: mini.z.optional(mini.z.string())
443
+ })
444
+ );
365
445
  var terms = (acceptance) => acceptance && { locale: acceptance.locale, terms_revision: acceptance.termsRevision };
366
446
  function createBonusApi(transport) {
367
447
  const listPage = (path, key, schema, auth, input, options) => transport.request({
@@ -429,7 +509,26 @@ function createBonusApi(transport) {
429
509
  auth: "required",
430
510
  schema: participationEnvelope(),
431
511
  options
432
- }).then((data) => data.participation)
512
+ }).then((data) => data.participation),
513
+ getOverview: (_params, options) => transport.request({
514
+ method: "GET",
515
+ path: "/bonus/overview",
516
+ auth: "required",
517
+ schema: overviewSchema(),
518
+ options
519
+ }),
520
+ listPositions: (input, options) => transport.request({
521
+ method: "GET",
522
+ path: "/bonus/positions",
523
+ query: { limit: input?.pageSize, cursor: input?.cursor, state: input?.state, currency: input?.currency },
524
+ auth: "required",
525
+ schema: positionsPage(),
526
+ options
527
+ }).then(({ rows, nextCursor }) => {
528
+ const page = { items: rows };
529
+ if (nextCursor) page.nextCursor = nextCursor;
530
+ return page;
531
+ })
433
532
  };
434
533
  }
435
534
  var gameSchema = /* @__PURE__ */ extension.lazy(
@@ -785,150 +884,122 @@ function createMissionsApi(transport) {
785
884
  })
786
885
  };
787
886
  }
788
- var STATUSES = ["pending", "qualified", "completed", "expired", "unspecified"];
789
- var status = () => mini.z.pipe(protoEnum("REFERRAL_STATUS_"), mini.z.enum(STATUSES));
790
887
  var DEFAULT_PER_PAGE = 20;
791
- var count2 = () => mini.z._default(mini.z.number().check(mini.z.refine((value) => Number.isInteger(value) && value >= 0, "invalid counter")), 0);
792
888
  var HISTORY_PATH = "/referrals/history";
793
- var REGISTER_ROUTE = { method: "POST", path: "/referrals/register" };
794
- function maskEmail(value) {
795
- if (typeof value !== "string") return null;
796
- const email = value.trim();
797
- const parts = email.split("@");
798
- if (parts.length !== 2 || /\s/.test(email)) return null;
799
- const [local, domain] = parts;
800
- if (local === "" || domain === "") return null;
801
- const chars = Array.from(local);
802
- return `${chars.length === 1 ? "*" : chars[0] + "*".repeat(chars.length - 1)}@${domain}`;
803
- }
889
+ var count2 = () => mini.z._default(mini.z.number().check(mini.z.refine((value) => Number.isSafeInteger(value) && value >= 0, "invalid counter")), 0);
890
+ var money3 = () => mini.z.pipe(
891
+ mini.z.nullish(extension.wire({ minor_units: minorUnits(), currency: mini.z._default(currencyOrEmpty(), "") })),
892
+ mini.z.transform(
893
+ (value) => value == null ? null : { amount: value.minorUnits, currency: value.currency }
894
+ )
895
+ );
896
+ var rulesSchema = () => mini.z.pipe(
897
+ mini.z.nullish(
898
+ extension.wire({
899
+ reward: money3(),
900
+ minimum_real_net_loss: money3(),
901
+ referee_window_days: count2(),
902
+ hold_hours: count2(),
903
+ wagering_multiplier: mini.z._default(mini.z.string(), ""),
904
+ maximum_conversion: money3()
905
+ })
906
+ ),
907
+ mini.z.transform((rules) => {
908
+ if (rules == null || rules.reward === null || rules.minimumRealNetLoss === null) return null;
909
+ return {
910
+ reward: rules.reward,
911
+ minimumRealNetLoss: rules.minimumRealNetLoss,
912
+ refereeWindowDays: rules.refereeWindowDays,
913
+ holdHours: rules.holdHours,
914
+ wageringMultiplier: rules.wageringMultiplier,
915
+ maximumConversion: rules.maximumConversion
916
+ };
917
+ })
918
+ );
804
919
  var infoSchema = /* @__PURE__ */ extension.lazy(
805
920
  () => mini.z.pipe(
806
921
  extension.wire({
922
+ enabled: mini.z._default(mini.z.boolean(), false),
807
923
  referral_code: optionalText(),
808
- referral_link: optionalText(),
809
- total_referrals: count2(),
810
- completed_referrals: count2(),
811
- pending_referrals: count2(),
812
- total_earned: majorUnits(),
813
- bonus_per_referral: majorUnits(),
814
- min_deposit: majorUnits()
924
+ rules: rulesSchema(),
925
+ totals: mini.z._default(
926
+ extension.wire({
927
+ registered: count2(),
928
+ deposited: count2(),
929
+ in_hold: count2(),
930
+ paid: count2(),
931
+ not_eligible: count2(),
932
+ expired: count2(),
933
+ cancelled: count2()
934
+ }),
935
+ { registered: 0, deposited: 0, inHold: 0, paid: 0, notEligible: 0, expired: 0, cancelled: 0 }
936
+ )
815
937
  }),
816
938
  mini.z.transform(
817
- ({ referralCode, referralLink, ...rest }) => ({
818
- code: referralCode,
819
- link: referralLink,
820
- ...rest
821
- })
939
+ ({ enabled, referralCode, rules, totals }) => ({ enabled, code: referralCode, rules, totals })
822
940
  )
823
941
  )
824
942
  );
825
- var MinorAmount = class {
826
- constructor(value) {
827
- this.value = value;
828
- }
829
- value;
830
- };
831
- var minorAmount = () => mini.z.pipe(
832
- majorUnits(),
833
- mini.z.transform((value) => new MinorAmount(value))
834
- );
835
- var BUILT = /* @__PURE__ */ new WeakSet();
836
- var referralSchema = /* @__PURE__ */ extension.lazy(
837
- () => mini.z.pipe(
943
+ function remainingOf(target, loss) {
944
+ const missing = BigInt(target.amount) - BigInt(loss.amount);
945
+ return { amount: missing > 0n ? Number(missing) : 0, currency: target.currency };
946
+ }
947
+ var progressSchema = () => mini.z.pipe(
948
+ mini.z.nullish(
838
949
  extension.wire({
839
- id: mini.z.string(),
840
- referee_id: mini.z.optional(mini.z.string()),
841
- referee_email: mini.z.nullish(mini.z.string()),
842
- referee_name: optionalText(),
843
- referral_code: mini.z._default(mini.z.string(), ""),
844
- status: status(),
845
- referrer_bonus: minorAmount(),
846
- referee_bonus: minorAmount(),
847
- created_at: optionalTimestamp(),
848
- completed_at: optionalTimestamp(),
849
- expires_at: optionalTimestamp()
850
- }),
851
- mini.z.transform((r) => {
852
- const referrerBonus = r.referrerBonus;
853
- const refereeBonus = r.refereeBonus;
854
- if (!(referrerBonus instanceof MinorAmount) || !(refereeBonus instanceof MinorAmount)) return null;
855
- const item = {
856
- id: r.id,
857
- refereeName: r.refereeName,
858
- refereeEmailMasked: maskEmail(r.refereeEmail),
859
- code: r.referralCode,
860
- status: r.status,
861
- referrerBonus: referrerBonus.value,
862
- refereeBonus: refereeBonus.value,
863
- createdAt: r.createdAt,
864
- completedAt: r.completedAt,
865
- expiresAt: r.expiresAt
866
- };
867
- BUILT.add(item);
868
- return item;
950
+ deposit_done: mini.z._default(mini.z.boolean(), false),
951
+ real_net_loss: money3(),
952
+ target: money3(),
953
+ remaining: money3()
869
954
  })
870
- )
955
+ ),
956
+ mini.z.transform((progress) => {
957
+ if (progress == null || progress.target === null) return null;
958
+ const { target } = progress;
959
+ const realNetLoss = progress.realNetLoss ?? { amount: 0, currency: target.currency };
960
+ return {
961
+ depositDone: progress.depositDone,
962
+ realNetLoss,
963
+ target,
964
+ remaining: progress.remaining ?? remainingOf(target, realNetLoss)
965
+ };
966
+ })
871
967
  );
872
- function rawReferral(value) {
873
- if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
874
- const snake = {};
875
- for (const [key, field] of Object.entries(value)) snake[key.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`)] = field;
876
- const result = referralSchema().safeParse(snake);
877
- return result.success ? result.data : null;
968
+ var LEGACY_STATUS = { COMPLETED: "paid", EXPIRED: "expired", PENDING: "registered" };
969
+ function statusOf(playerStatus, legacy) {
970
+ if (playerStatus !== null) return playerStatus.replace(/^CAMPAIGN_REFERRAL_STATUS_/, "").toLowerCase();
971
+ return LEGACY_STATUS[(legacy ?? "").toUpperCase()] ?? "registered";
878
972
  }
879
- function historyItems(list2) {
880
- if (!Array.isArray(list2)) return [];
881
- const items = [];
882
- for (const entry of list2) {
883
- const item = typeof entry === "object" && entry !== null && BUILT.has(entry) ? entry : rawReferral(entry);
884
- if (item !== null) items.push(item);
885
- }
886
- return items;
887
- }
888
- var reportedTotal = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : 0;
973
+ var referralSchema = () => mini.z.pipe(
974
+ extension.wire({
975
+ id: mini.z.string(),
976
+ referee_name: optionalText(),
977
+ status: optionalText(),
978
+ player_status: optionalText(),
979
+ created_at: optionalTimestamp(),
980
+ deadline_at: optionalTimestamp(),
981
+ progress: progressSchema()
982
+ }),
983
+ mini.z.transform(
984
+ (r) => ({
985
+ id: r.id,
986
+ refereeName: r.refereeName,
987
+ status: statusOf(r.playerStatus, r.status),
988
+ createdAt: r.createdAt,
989
+ deadlineAt: r.deadlineAt,
990
+ progress: r.progress
991
+ })
992
+ )
993
+ );
889
994
  var historySchema = /* @__PURE__ */ extension.lazy(
890
995
  () => extension.wire({
996
+ referral_code: optionalText(),
891
997
  referrals: nullableList(referralSchema()),
892
- completed_count: count2(),
893
- total_earned: majorUnits(),
894
- pagination: mini.z.optional(
895
- extension.wire({
896
- page: count2(),
897
- page_size: count2(),
898
- total_items: count2(),
899
- total_pages: count2()
900
- })
901
- )
998
+ pagination: mini.z.optional(extension.wire({ page: count2(), limit: count2(), total_items: count2() }))
902
999
  })
903
1000
  );
904
- var registeredSchema = /* @__PURE__ */ extension.lazy(
905
- () => mini.z.pipe(
906
- extension.wire({
907
- id: mini.z.string(),
908
- referral_code: mini.z._default(mini.z.string(), ""),
909
- status: status(),
910
- referee_bonus: mini.z._default(majorUnits(), 0),
911
- created_at: optionalTimestamp()
912
- }),
913
- mini.z.transform(
914
- (r) => ({
915
- id: r.id,
916
- code: r.referralCode,
917
- status: r.status,
918
- refereeBonus: r.refereeBonus,
919
- createdAt: r.createdAt
920
- })
921
- )
922
- )
923
- );
924
1001
  var positiveInt = (value, fallback) => typeof value === "number" && Number.isSafeInteger(value) && value >= 1 ? value : fallback;
925
- function registerInputProblem(input) {
926
- if (typeof input !== "object" || input === null || Array.isArray(input))
927
- return "referrals.register: input must be an object { code }.";
928
- const { code } = input;
929
- if (typeof code !== "string" || code.trim() === "") return "referrals.register: code must be non-empty text.";
930
- return void 0;
931
- }
1002
+ var reportedTotal = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : 0;
932
1003
  function createReferralsApi(transport) {
933
1004
  return {
934
1005
  get: (_params, options) => transport.request({ method: "GET", path: "/referrals", auth: "required", schema: infoSchema(), options }),
@@ -944,12 +1015,11 @@ function createReferralsApi(transport) {
944
1015
  auth: "required",
945
1016
  schema: historySchema(),
946
1017
  options
947
- }).then(({ referrals, completedCount, totalEarned, pagination }) => {
948
- const items = historyItems(referrals);
949
- const received = Array.isArray(referrals) ? referrals.length : 0;
1018
+ }).then(({ referralCode, referrals, pagination }) => {
1019
+ const items = Array.isArray(referrals) ? referrals : [];
950
1020
  const page = positiveInt(pagination?.page, requestedPage ?? 1);
951
- const perPage = positiveInt(pagination?.pageSize, requestedPerPage ?? DEFAULT_PER_PAGE);
952
- const seen = received > 0 ? (page - 1) * perPage + received : 0;
1021
+ const perPage = positiveInt(pagination?.limit, requestedPerPage ?? DEFAULT_PER_PAGE);
1022
+ const seen = items.length > 0 ? (page - 1) * perPage + items.length : 0;
953
1023
  const totalItems = Math.max(reportedTotal(pagination?.totalItems), seen);
954
1024
  return {
955
1025
  items,
@@ -957,21 +1027,9 @@ function createReferralsApi(transport) {
957
1027
  perPage,
958
1028
  totalItems,
959
1029
  totalPages: totalItems > 0 ? Math.ceil(totalItems / perPage) : 0,
960
- completedCount,
961
- totalEarned
1030
+ code: referralCode
962
1031
  };
963
1032
  });
964
- },
965
- register: (input, options) => {
966
- const problem = registerInputProblem(input);
967
- if (problem !== void 0) return rejectInput(transport, problem, REGISTER_ROUTE);
968
- return transport.request({
969
- ...REGISTER_ROUTE,
970
- body: { referral_code: input.code.trim() },
971
- auth: "required",
972
- schema: registeredSchema(),
973
- options
974
- });
975
1033
  }
976
1034
  };
977
1035
  }