@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/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EnginexError } from '@getenginex/sdk';
2
2
  import * as extension from '@getenginex/sdk/extension';
3
- import { lazy, wire, decimalPlaces, currencyCode, money as money$1, strictValue, moneyText } from '@getenginex/sdk/extension';
3
+ import { lazy, wire, decimalPlaces, currencyCode, money as money$1, moneyText } from '@getenginex/sdk/extension';
4
4
  import { z } from 'zod/mini';
5
5
 
6
6
  // src/client.ts
@@ -47,20 +47,6 @@ function durationSeconds() {
47
47
  z.transform((value) => Number(value.slice(0, -1)))
48
48
  );
49
49
  }
50
- var MAJOR_UNITS = "Expected a value in major units (a finite number) that fits in whole minor units";
51
- function majorToMinorUnits(value) {
52
- const minor = Math.sign(value) * Math.round(Math.abs(value) * 100);
53
- return minor === 0 ? 0 : minor;
54
- }
55
- function majorUnits() {
56
- return z.pipe(
57
- strictValue(
58
- (value) => typeof value === "number" && Number.isSafeInteger(majorToMinorUnits(value)),
59
- MAJOR_UNITS
60
- ),
61
- z.transform((value) => majorToMinorUnits(value))
62
- );
63
- }
64
50
 
65
51
  // src/modules/bonus.ts
66
52
  var campaignCurrency = () => z._default(currencyOrEmpty(), "");
@@ -877,150 +863,122 @@ function createMissionsApi(transport) {
877
863
  })
878
864
  };
879
865
  }
880
- var STATUSES = ["pending", "qualified", "completed", "expired", "unspecified"];
881
- var status = () => z.pipe(protoEnum("REFERRAL_STATUS_"), z.enum(STATUSES));
882
866
  var DEFAULT_PER_PAGE = 20;
883
- var count2 = () => z._default(z.number().check(z.refine((value) => Number.isInteger(value) && value >= 0, "invalid counter")), 0);
884
867
  var HISTORY_PATH = "/referrals/history";
885
- var REGISTER_ROUTE = { method: "POST", path: "/referrals/register" };
886
- function maskEmail(value) {
887
- if (typeof value !== "string") return null;
888
- const email = value.trim();
889
- const parts = email.split("@");
890
- if (parts.length !== 2 || /\s/.test(email)) return null;
891
- const [local, domain] = parts;
892
- if (local === "" || domain === "") return null;
893
- const chars = Array.from(local);
894
- return `${chars.length === 1 ? "*" : chars[0] + "*".repeat(chars.length - 1)}@${domain}`;
895
- }
868
+ var count2 = () => z._default(z.number().check(z.refine((value) => Number.isSafeInteger(value) && value >= 0, "invalid counter")), 0);
869
+ var money3 = () => z.pipe(
870
+ z.nullish(wire({ minor_units: minorUnits(), currency: z._default(currencyOrEmpty(), "") })),
871
+ z.transform(
872
+ (value) => value == null ? null : { amount: value.minorUnits, currency: value.currency }
873
+ )
874
+ );
875
+ var rulesSchema = () => z.pipe(
876
+ z.nullish(
877
+ wire({
878
+ reward: money3(),
879
+ minimum_real_net_loss: money3(),
880
+ referee_window_days: count2(),
881
+ hold_hours: count2(),
882
+ wagering_multiplier: z._default(z.string(), ""),
883
+ maximum_conversion: money3()
884
+ })
885
+ ),
886
+ z.transform((rules) => {
887
+ if (rules == null || rules.reward === null || rules.minimumRealNetLoss === null) return null;
888
+ return {
889
+ reward: rules.reward,
890
+ minimumRealNetLoss: rules.minimumRealNetLoss,
891
+ refereeWindowDays: rules.refereeWindowDays,
892
+ holdHours: rules.holdHours,
893
+ wageringMultiplier: rules.wageringMultiplier,
894
+ maximumConversion: rules.maximumConversion
895
+ };
896
+ })
897
+ );
896
898
  var infoSchema = /* @__PURE__ */ lazy(
897
899
  () => z.pipe(
898
900
  wire({
901
+ enabled: z._default(z.boolean(), false),
899
902
  referral_code: optionalText(),
900
- referral_link: optionalText(),
901
- total_referrals: count2(),
902
- completed_referrals: count2(),
903
- pending_referrals: count2(),
904
- total_earned: majorUnits(),
905
- bonus_per_referral: majorUnits(),
906
- min_deposit: majorUnits()
903
+ rules: rulesSchema(),
904
+ totals: z._default(
905
+ wire({
906
+ registered: count2(),
907
+ deposited: count2(),
908
+ in_hold: count2(),
909
+ paid: count2(),
910
+ not_eligible: count2(),
911
+ expired: count2(),
912
+ cancelled: count2()
913
+ }),
914
+ { registered: 0, deposited: 0, inHold: 0, paid: 0, notEligible: 0, expired: 0, cancelled: 0 }
915
+ )
907
916
  }),
908
917
  z.transform(
909
- ({ referralCode, referralLink, ...rest }) => ({
910
- code: referralCode,
911
- link: referralLink,
912
- ...rest
913
- })
918
+ ({ enabled, referralCode, rules, totals }) => ({ enabled, code: referralCode, rules, totals })
914
919
  )
915
920
  )
916
921
  );
917
- var MinorAmount = class {
918
- constructor(value) {
919
- this.value = value;
920
- }
921
- value;
922
- };
923
- var minorAmount = () => z.pipe(
924
- majorUnits(),
925
- z.transform((value) => new MinorAmount(value))
926
- );
927
- var BUILT = /* @__PURE__ */ new WeakSet();
928
- var referralSchema = /* @__PURE__ */ lazy(
929
- () => z.pipe(
922
+ function remainingOf(target, loss) {
923
+ const missing = BigInt(target.amount) - BigInt(loss.amount);
924
+ return { amount: missing > 0n ? Number(missing) : 0, currency: target.currency };
925
+ }
926
+ var progressSchema = () => z.pipe(
927
+ z.nullish(
930
928
  wire({
931
- id: z.string(),
932
- referee_id: z.optional(z.string()),
933
- referee_email: z.nullish(z.string()),
934
- referee_name: optionalText(),
935
- referral_code: z._default(z.string(), ""),
936
- status: status(),
937
- referrer_bonus: minorAmount(),
938
- referee_bonus: minorAmount(),
939
- created_at: optionalTimestamp(),
940
- completed_at: optionalTimestamp(),
941
- expires_at: optionalTimestamp()
942
- }),
943
- z.transform((r) => {
944
- const referrerBonus = r.referrerBonus;
945
- const refereeBonus = r.refereeBonus;
946
- if (!(referrerBonus instanceof MinorAmount) || !(refereeBonus instanceof MinorAmount)) return null;
947
- const item = {
948
- id: r.id,
949
- refereeName: r.refereeName,
950
- refereeEmailMasked: maskEmail(r.refereeEmail),
951
- code: r.referralCode,
952
- status: r.status,
953
- referrerBonus: referrerBonus.value,
954
- refereeBonus: refereeBonus.value,
955
- createdAt: r.createdAt,
956
- completedAt: r.completedAt,
957
- expiresAt: r.expiresAt
958
- };
959
- BUILT.add(item);
960
- return item;
929
+ deposit_done: z._default(z.boolean(), false),
930
+ real_net_loss: money3(),
931
+ target: money3(),
932
+ remaining: money3()
961
933
  })
962
- )
934
+ ),
935
+ z.transform((progress) => {
936
+ if (progress == null || progress.target === null) return null;
937
+ const { target } = progress;
938
+ const realNetLoss = progress.realNetLoss ?? { amount: 0, currency: target.currency };
939
+ return {
940
+ depositDone: progress.depositDone,
941
+ realNetLoss,
942
+ target,
943
+ remaining: progress.remaining ?? remainingOf(target, realNetLoss)
944
+ };
945
+ })
963
946
  );
964
- function rawReferral(value) {
965
- if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
966
- const snake = {};
967
- for (const [key, field] of Object.entries(value)) snake[key.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`)] = field;
968
- const result = referralSchema().safeParse(snake);
969
- return result.success ? result.data : null;
947
+ var LEGACY_STATUS = { COMPLETED: "paid", EXPIRED: "expired", PENDING: "registered" };
948
+ function statusOf(playerStatus, legacy) {
949
+ if (playerStatus !== null) return playerStatus.replace(/^CAMPAIGN_REFERRAL_STATUS_/, "").toLowerCase();
950
+ return LEGACY_STATUS[(legacy ?? "").toUpperCase()] ?? "registered";
970
951
  }
971
- function historyItems(list2) {
972
- if (!Array.isArray(list2)) return [];
973
- const items = [];
974
- for (const entry of list2) {
975
- const item = typeof entry === "object" && entry !== null && BUILT.has(entry) ? entry : rawReferral(entry);
976
- if (item !== null) items.push(item);
977
- }
978
- return items;
979
- }
980
- var reportedTotal = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : 0;
952
+ var referralSchema = () => z.pipe(
953
+ wire({
954
+ id: z.string(),
955
+ referee_name: optionalText(),
956
+ status: optionalText(),
957
+ player_status: optionalText(),
958
+ created_at: optionalTimestamp(),
959
+ deadline_at: optionalTimestamp(),
960
+ progress: progressSchema()
961
+ }),
962
+ z.transform(
963
+ (r) => ({
964
+ id: r.id,
965
+ refereeName: r.refereeName,
966
+ status: statusOf(r.playerStatus, r.status),
967
+ createdAt: r.createdAt,
968
+ deadlineAt: r.deadlineAt,
969
+ progress: r.progress
970
+ })
971
+ )
972
+ );
981
973
  var historySchema = /* @__PURE__ */ lazy(
982
974
  () => wire({
975
+ referral_code: optionalText(),
983
976
  referrals: nullableList(referralSchema()),
984
- completed_count: count2(),
985
- total_earned: majorUnits(),
986
- pagination: z.optional(
987
- wire({
988
- page: count2(),
989
- page_size: count2(),
990
- total_items: count2(),
991
- total_pages: count2()
992
- })
993
- )
977
+ pagination: z.optional(wire({ page: count2(), limit: count2(), total_items: count2() }))
994
978
  })
995
979
  );
996
- var registeredSchema = /* @__PURE__ */ lazy(
997
- () => z.pipe(
998
- wire({
999
- id: z.string(),
1000
- referral_code: z._default(z.string(), ""),
1001
- status: status(),
1002
- referee_bonus: z._default(majorUnits(), 0),
1003
- created_at: optionalTimestamp()
1004
- }),
1005
- z.transform(
1006
- (r) => ({
1007
- id: r.id,
1008
- code: r.referralCode,
1009
- status: r.status,
1010
- refereeBonus: r.refereeBonus,
1011
- createdAt: r.createdAt
1012
- })
1013
- )
1014
- )
1015
- );
1016
980
  var positiveInt = (value, fallback) => typeof value === "number" && Number.isSafeInteger(value) && value >= 1 ? value : fallback;
1017
- function registerInputProblem(input) {
1018
- if (typeof input !== "object" || input === null || Array.isArray(input))
1019
- return "referrals.register: input must be an object { code }.";
1020
- const { code } = input;
1021
- if (typeof code !== "string" || code.trim() === "") return "referrals.register: code must be non-empty text.";
1022
- return void 0;
1023
- }
981
+ var reportedTotal = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : 0;
1024
982
  function createReferralsApi(transport) {
1025
983
  return {
1026
984
  get: (_params, options) => transport.request({ method: "GET", path: "/referrals", auth: "required", schema: infoSchema(), options }),
@@ -1036,12 +994,11 @@ function createReferralsApi(transport) {
1036
994
  auth: "required",
1037
995
  schema: historySchema(),
1038
996
  options
1039
- }).then(({ referrals, completedCount, totalEarned, pagination }) => {
1040
- const items = historyItems(referrals);
1041
- const received = Array.isArray(referrals) ? referrals.length : 0;
997
+ }).then(({ referralCode, referrals, pagination }) => {
998
+ const items = Array.isArray(referrals) ? referrals : [];
1042
999
  const page = positiveInt(pagination?.page, requestedPage ?? 1);
1043
- const perPage = positiveInt(pagination?.pageSize, requestedPerPage ?? DEFAULT_PER_PAGE);
1044
- const seen = received > 0 ? (page - 1) * perPage + received : 0;
1000
+ const perPage = positiveInt(pagination?.limit, requestedPerPage ?? DEFAULT_PER_PAGE);
1001
+ const seen = items.length > 0 ? (page - 1) * perPage + items.length : 0;
1045
1002
  const totalItems = Math.max(reportedTotal(pagination?.totalItems), seen);
1046
1003
  return {
1047
1004
  items,
@@ -1049,21 +1006,9 @@ function createReferralsApi(transport) {
1049
1006
  perPage,
1050
1007
  totalItems,
1051
1008
  totalPages: totalItems > 0 ? Math.ceil(totalItems / perPage) : 0,
1052
- completedCount,
1053
- totalEarned
1009
+ code: referralCode
1054
1010
  };
1055
1011
  });
1056
- },
1057
- register: (input, options) => {
1058
- const problem = registerInputProblem(input);
1059
- if (problem !== void 0) return rejectInput(transport, problem, REGISTER_ROUTE);
1060
- return transport.request({
1061
- ...REGISTER_ROUTE,
1062
- body: { referral_code: input.code.trim() },
1063
- auth: "required",
1064
- schema: registeredSchema(),
1065
- options
1066
- });
1067
1012
  }
1068
1013
  };
1069
1014
  }