@getenginex/sdk-igaming 0.7.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,21 @@
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
+
3
19
  ## 0.7.0
4
20
 
5
21
  ### 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(), "");
@@ -898,150 +884,122 @@ function createMissionsApi(transport) {
898
884
  })
899
885
  };
900
886
  }
901
- var STATUSES = ["pending", "qualified", "completed", "expired", "unspecified"];
902
- var status = () => mini.z.pipe(protoEnum("REFERRAL_STATUS_"), mini.z.enum(STATUSES));
903
887
  var DEFAULT_PER_PAGE = 20;
904
- var count2 = () => mini.z._default(mini.z.number().check(mini.z.refine((value) => Number.isInteger(value) && value >= 0, "invalid counter")), 0);
905
888
  var HISTORY_PATH = "/referrals/history";
906
- var REGISTER_ROUTE = { method: "POST", path: "/referrals/register" };
907
- function maskEmail(value) {
908
- if (typeof value !== "string") return null;
909
- const email = value.trim();
910
- const parts = email.split("@");
911
- if (parts.length !== 2 || /\s/.test(email)) return null;
912
- const [local, domain] = parts;
913
- if (local === "" || domain === "") return null;
914
- const chars = Array.from(local);
915
- return `${chars.length === 1 ? "*" : chars[0] + "*".repeat(chars.length - 1)}@${domain}`;
916
- }
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
+ );
917
919
  var infoSchema = /* @__PURE__ */ extension.lazy(
918
920
  () => mini.z.pipe(
919
921
  extension.wire({
922
+ enabled: mini.z._default(mini.z.boolean(), false),
920
923
  referral_code: optionalText(),
921
- referral_link: optionalText(),
922
- total_referrals: count2(),
923
- completed_referrals: count2(),
924
- pending_referrals: count2(),
925
- total_earned: majorUnits(),
926
- bonus_per_referral: majorUnits(),
927
- 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
+ )
928
937
  }),
929
938
  mini.z.transform(
930
- ({ referralCode, referralLink, ...rest }) => ({
931
- code: referralCode,
932
- link: referralLink,
933
- ...rest
934
- })
939
+ ({ enabled, referralCode, rules, totals }) => ({ enabled, code: referralCode, rules, totals })
935
940
  )
936
941
  )
937
942
  );
938
- var MinorAmount = class {
939
- constructor(value) {
940
- this.value = value;
941
- }
942
- value;
943
- };
944
- var minorAmount = () => mini.z.pipe(
945
- majorUnits(),
946
- mini.z.transform((value) => new MinorAmount(value))
947
- );
948
- var BUILT = /* @__PURE__ */ new WeakSet();
949
- var referralSchema = /* @__PURE__ */ extension.lazy(
950
- () => 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(
951
949
  extension.wire({
952
- id: mini.z.string(),
953
- referee_id: mini.z.optional(mini.z.string()),
954
- referee_email: mini.z.nullish(mini.z.string()),
955
- referee_name: optionalText(),
956
- referral_code: mini.z._default(mini.z.string(), ""),
957
- status: status(),
958
- referrer_bonus: minorAmount(),
959
- referee_bonus: minorAmount(),
960
- created_at: optionalTimestamp(),
961
- completed_at: optionalTimestamp(),
962
- expires_at: optionalTimestamp()
963
- }),
964
- mini.z.transform((r) => {
965
- const referrerBonus = r.referrerBonus;
966
- const refereeBonus = r.refereeBonus;
967
- if (!(referrerBonus instanceof MinorAmount) || !(refereeBonus instanceof MinorAmount)) return null;
968
- const item = {
969
- id: r.id,
970
- refereeName: r.refereeName,
971
- refereeEmailMasked: maskEmail(r.refereeEmail),
972
- code: r.referralCode,
973
- status: r.status,
974
- referrerBonus: referrerBonus.value,
975
- refereeBonus: refereeBonus.value,
976
- createdAt: r.createdAt,
977
- completedAt: r.completedAt,
978
- expiresAt: r.expiresAt
979
- };
980
- BUILT.add(item);
981
- return item;
950
+ deposit_done: mini.z._default(mini.z.boolean(), false),
951
+ real_net_loss: money3(),
952
+ target: money3(),
953
+ remaining: money3()
982
954
  })
983
- )
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
+ })
984
967
  );
985
- function rawReferral(value) {
986
- if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
987
- const snake = {};
988
- for (const [key, field] of Object.entries(value)) snake[key.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`)] = field;
989
- const result = referralSchema().safeParse(snake);
990
- 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";
991
972
  }
992
- function historyItems(list2) {
993
- if (!Array.isArray(list2)) return [];
994
- const items = [];
995
- for (const entry of list2) {
996
- const item = typeof entry === "object" && entry !== null && BUILT.has(entry) ? entry : rawReferral(entry);
997
- if (item !== null) items.push(item);
998
- }
999
- return items;
1000
- }
1001
- 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
+ );
1002
994
  var historySchema = /* @__PURE__ */ extension.lazy(
1003
995
  () => extension.wire({
996
+ referral_code: optionalText(),
1004
997
  referrals: nullableList(referralSchema()),
1005
- completed_count: count2(),
1006
- total_earned: majorUnits(),
1007
- pagination: mini.z.optional(
1008
- extension.wire({
1009
- page: count2(),
1010
- page_size: count2(),
1011
- total_items: count2(),
1012
- total_pages: count2()
1013
- })
1014
- )
998
+ pagination: mini.z.optional(extension.wire({ page: count2(), limit: count2(), total_items: count2() }))
1015
999
  })
1016
1000
  );
1017
- var registeredSchema = /* @__PURE__ */ extension.lazy(
1018
- () => mini.z.pipe(
1019
- extension.wire({
1020
- id: mini.z.string(),
1021
- referral_code: mini.z._default(mini.z.string(), ""),
1022
- status: status(),
1023
- referee_bonus: mini.z._default(majorUnits(), 0),
1024
- created_at: optionalTimestamp()
1025
- }),
1026
- mini.z.transform(
1027
- (r) => ({
1028
- id: r.id,
1029
- code: r.referralCode,
1030
- status: r.status,
1031
- refereeBonus: r.refereeBonus,
1032
- createdAt: r.createdAt
1033
- })
1034
- )
1035
- )
1036
- );
1037
1001
  var positiveInt = (value, fallback) => typeof value === "number" && Number.isSafeInteger(value) && value >= 1 ? value : fallback;
1038
- function registerInputProblem(input) {
1039
- if (typeof input !== "object" || input === null || Array.isArray(input))
1040
- return "referrals.register: input must be an object { code }.";
1041
- const { code } = input;
1042
- if (typeof code !== "string" || code.trim() === "") return "referrals.register: code must be non-empty text.";
1043
- return void 0;
1044
- }
1002
+ var reportedTotal = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : 0;
1045
1003
  function createReferralsApi(transport) {
1046
1004
  return {
1047
1005
  get: (_params, options) => transport.request({ method: "GET", path: "/referrals", auth: "required", schema: infoSchema(), options }),
@@ -1057,12 +1015,11 @@ function createReferralsApi(transport) {
1057
1015
  auth: "required",
1058
1016
  schema: historySchema(),
1059
1017
  options
1060
- }).then(({ referrals, completedCount, totalEarned, pagination }) => {
1061
- const items = historyItems(referrals);
1062
- const received = Array.isArray(referrals) ? referrals.length : 0;
1018
+ }).then(({ referralCode, referrals, pagination }) => {
1019
+ const items = Array.isArray(referrals) ? referrals : [];
1063
1020
  const page = positiveInt(pagination?.page, requestedPage ?? 1);
1064
- const perPage = positiveInt(pagination?.pageSize, requestedPerPage ?? DEFAULT_PER_PAGE);
1065
- 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;
1066
1023
  const totalItems = Math.max(reportedTotal(pagination?.totalItems), seen);
1067
1024
  return {
1068
1025
  items,
@@ -1070,21 +1027,9 @@ function createReferralsApi(transport) {
1070
1027
  perPage,
1071
1028
  totalItems,
1072
1029
  totalPages: totalItems > 0 ? Math.ceil(totalItems / perPage) : 0,
1073
- completedCount,
1074
- totalEarned
1030
+ code: referralCode
1075
1031
  };
1076
1032
  });
1077
- },
1078
- register: (input, options) => {
1079
- const problem = registerInputProblem(input);
1080
- if (problem !== void 0) return rejectInput(transport, problem, REGISTER_ROUTE);
1081
- return transport.request({
1082
- ...REGISTER_ROUTE,
1083
- body: { referral_code: input.code.trim() },
1084
- auth: "required",
1085
- schema: registeredSchema(),
1086
- options
1087
- });
1088
1033
  }
1089
1034
  };
1090
1035
  }