@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/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(), "");
@@ -273,6 +259,39 @@ var offerSchema = /* @__PURE__ */ lazy(
273
259
  content: z.optional(content())
274
260
  })
275
261
  );
262
+ function grantMoney(value, currency) {
263
+ return { amount: value?.amount ?? 0, currency: value?.currency || currency };
264
+ }
265
+ var rewardGrant = () => z.pipe(
266
+ wire({
267
+ state: protoEnum("CAMPAIGN_PLAYER_REWARD_GRANT_STATE_"),
268
+ granted: z.optional(money()),
269
+ balance: z.optional(money()),
270
+ converted: z.optional(money()),
271
+ expires_at: z.optional(z.string()),
272
+ wagering: z.optional(
273
+ wire({ required: z.optional(money()), accumulated: z.optional(money()), completed_at: z.optional(z.string()) })
274
+ )
275
+ }),
276
+ z.transform(({ state, granted, balance, converted, expiresAt, wagering }) => {
277
+ const currency = [granted, balance, converted, wagering?.required, wagering?.accumulated].find((m) => m?.currency)?.currency ?? "";
278
+ const out = {
279
+ state,
280
+ granted: grantMoney(granted, currency),
281
+ balance: grantMoney(balance, currency),
282
+ converted: grantMoney(converted, currency)
283
+ };
284
+ if (expiresAt !== void 0) out.expiresAt = expiresAt;
285
+ if (wagering) {
286
+ out.wagering = {
287
+ required: grantMoney(wagering.required, currency),
288
+ accumulated: grantMoney(wagering.accumulated, currency)
289
+ };
290
+ if (wagering.completedAt !== void 0) out.wagering.completedAt = wagering.completedAt;
291
+ }
292
+ return out;
293
+ })
294
+ );
276
295
  var participationSchema = /* @__PURE__ */ lazy(
277
296
  () => z.pipe(
278
297
  wire({
@@ -290,6 +309,7 @@ var participationSchema = /* @__PURE__ */ lazy(
290
309
  reward_failed: z.optional(empty()),
291
310
  expired: z.optional(wire({ expired_at: z.optional(z.string()) })),
292
311
  cancelled: z.optional(empty()),
312
+ reward_grant: z.optional(rewardGrant()),
293
313
  snapshot: z.optional(
294
314
  wire({
295
315
  reward: z.optional(reward()),
@@ -341,6 +361,66 @@ function toCursorPage(key, data) {
341
361
  if (data.nextCursor) page.nextCursor = data.nextCursor;
342
362
  return page;
343
363
  }
364
+ var nullableDate = () => z.pipe(
365
+ z.nullish(z.string()),
366
+ z.transform((value) => value ?? void 0)
367
+ );
368
+ function compact(value) {
369
+ return Object.fromEntries(Object.entries(value).filter(([, v]) => v !== void 0));
370
+ }
371
+ var overviewSchema = /* @__PURE__ */ lazy(
372
+ () => z.pipe(
373
+ wire({
374
+ currencies: list(
375
+ z.pipe(
376
+ wire({
377
+ currency: currencyOrEmpty(),
378
+ decimal_places: z.number(),
379
+ restricted_total: minorUnits(),
380
+ expiring_7d: minorUnits(),
381
+ open_positions: z.number(),
382
+ next_expires_at: nullableDate(),
383
+ converted: minorUnits(),
384
+ converted_campaigns: z.number()
385
+ }),
386
+ z.transform(compact)
387
+ )
388
+ ),
389
+ as_of: nullableDate()
390
+ }),
391
+ z.transform(compact)
392
+ )
393
+ );
394
+ var positionsPage = /* @__PURE__ */ lazy(
395
+ () => wire({
396
+ rows: list(
397
+ z.pipe(
398
+ wire({
399
+ position_id: z.string(),
400
+ campaign_id: z.string(),
401
+ currency: currencyOrEmpty(),
402
+ decimal_places: z.number(),
403
+ granted: minorUnits(),
404
+ restricted: minorUnits(),
405
+ converted: minorUnits(),
406
+ required: minorUnits(),
407
+ wagered: minorUnits(),
408
+ remaining: minorUnits(),
409
+ state: z.string(),
410
+ // The gateway answers `null` for an action it does not know; known ones are uppercase (`CONVERT`).
411
+ terminal_action: z.pipe(
412
+ z.nullish(z.string()),
413
+ z.transform((value) => value ? value.toLowerCase() : void 0)
414
+ ),
415
+ expires_at: nullableDate(),
416
+ created_at: nullableDate()
417
+ }),
418
+ z.transform((row) => compact(row))
419
+ )
420
+ ),
421
+ next_cursor: z.optional(z.string())
422
+ })
423
+ );
344
424
  var terms = (acceptance) => acceptance && { locale: acceptance.locale, terms_revision: acceptance.termsRevision };
345
425
  function createBonusApi(transport) {
346
426
  const listPage = (path, key, schema, auth, input, options) => transport.request({
@@ -408,7 +488,26 @@ function createBonusApi(transport) {
408
488
  auth: "required",
409
489
  schema: participationEnvelope(),
410
490
  options
411
- }).then((data) => data.participation)
491
+ }).then((data) => data.participation),
492
+ getOverview: (_params, options) => transport.request({
493
+ method: "GET",
494
+ path: "/bonus/overview",
495
+ auth: "required",
496
+ schema: overviewSchema(),
497
+ options
498
+ }),
499
+ listPositions: (input, options) => transport.request({
500
+ method: "GET",
501
+ path: "/bonus/positions",
502
+ query: { limit: input?.pageSize, cursor: input?.cursor, state: input?.state, currency: input?.currency },
503
+ auth: "required",
504
+ schema: positionsPage(),
505
+ options
506
+ }).then(({ rows, nextCursor }) => {
507
+ const page = { items: rows };
508
+ if (nextCursor) page.nextCursor = nextCursor;
509
+ return page;
510
+ })
412
511
  };
413
512
  }
414
513
  var gameSchema = /* @__PURE__ */ lazy(
@@ -764,150 +863,122 @@ function createMissionsApi(transport) {
764
863
  })
765
864
  };
766
865
  }
767
- var STATUSES = ["pending", "qualified", "completed", "expired", "unspecified"];
768
- var status = () => z.pipe(protoEnum("REFERRAL_STATUS_"), z.enum(STATUSES));
769
866
  var DEFAULT_PER_PAGE = 20;
770
- var count2 = () => z._default(z.number().check(z.refine((value) => Number.isInteger(value) && value >= 0, "invalid counter")), 0);
771
867
  var HISTORY_PATH = "/referrals/history";
772
- var REGISTER_ROUTE = { method: "POST", path: "/referrals/register" };
773
- function maskEmail(value) {
774
- if (typeof value !== "string") return null;
775
- const email = value.trim();
776
- const parts = email.split("@");
777
- if (parts.length !== 2 || /\s/.test(email)) return null;
778
- const [local, domain] = parts;
779
- if (local === "" || domain === "") return null;
780
- const chars = Array.from(local);
781
- return `${chars.length === 1 ? "*" : chars[0] + "*".repeat(chars.length - 1)}@${domain}`;
782
- }
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
+ );
783
898
  var infoSchema = /* @__PURE__ */ lazy(
784
899
  () => z.pipe(
785
900
  wire({
901
+ enabled: z._default(z.boolean(), false),
786
902
  referral_code: optionalText(),
787
- referral_link: optionalText(),
788
- total_referrals: count2(),
789
- completed_referrals: count2(),
790
- pending_referrals: count2(),
791
- total_earned: majorUnits(),
792
- bonus_per_referral: majorUnits(),
793
- 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
+ )
794
916
  }),
795
917
  z.transform(
796
- ({ referralCode, referralLink, ...rest }) => ({
797
- code: referralCode,
798
- link: referralLink,
799
- ...rest
800
- })
918
+ ({ enabled, referralCode, rules, totals }) => ({ enabled, code: referralCode, rules, totals })
801
919
  )
802
920
  )
803
921
  );
804
- var MinorAmount = class {
805
- constructor(value) {
806
- this.value = value;
807
- }
808
- value;
809
- };
810
- var minorAmount = () => z.pipe(
811
- majorUnits(),
812
- z.transform((value) => new MinorAmount(value))
813
- );
814
- var BUILT = /* @__PURE__ */ new WeakSet();
815
- var referralSchema = /* @__PURE__ */ lazy(
816
- () => 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(
817
928
  wire({
818
- id: z.string(),
819
- referee_id: z.optional(z.string()),
820
- referee_email: z.nullish(z.string()),
821
- referee_name: optionalText(),
822
- referral_code: z._default(z.string(), ""),
823
- status: status(),
824
- referrer_bonus: minorAmount(),
825
- referee_bonus: minorAmount(),
826
- created_at: optionalTimestamp(),
827
- completed_at: optionalTimestamp(),
828
- expires_at: optionalTimestamp()
829
- }),
830
- z.transform((r) => {
831
- const referrerBonus = r.referrerBonus;
832
- const refereeBonus = r.refereeBonus;
833
- if (!(referrerBonus instanceof MinorAmount) || !(refereeBonus instanceof MinorAmount)) return null;
834
- const item = {
835
- id: r.id,
836
- refereeName: r.refereeName,
837
- refereeEmailMasked: maskEmail(r.refereeEmail),
838
- code: r.referralCode,
839
- status: r.status,
840
- referrerBonus: referrerBonus.value,
841
- refereeBonus: refereeBonus.value,
842
- createdAt: r.createdAt,
843
- completedAt: r.completedAt,
844
- expiresAt: r.expiresAt
845
- };
846
- BUILT.add(item);
847
- return item;
929
+ deposit_done: z._default(z.boolean(), false),
930
+ real_net_loss: money3(),
931
+ target: money3(),
932
+ remaining: money3()
848
933
  })
849
- )
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
+ })
850
946
  );
851
- function rawReferral(value) {
852
- if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
853
- const snake = {};
854
- for (const [key, field] of Object.entries(value)) snake[key.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`)] = field;
855
- const result = referralSchema().safeParse(snake);
856
- 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";
857
951
  }
858
- function historyItems(list2) {
859
- if (!Array.isArray(list2)) return [];
860
- const items = [];
861
- for (const entry of list2) {
862
- const item = typeof entry === "object" && entry !== null && BUILT.has(entry) ? entry : rawReferral(entry);
863
- if (item !== null) items.push(item);
864
- }
865
- return items;
866
- }
867
- 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
+ );
868
973
  var historySchema = /* @__PURE__ */ lazy(
869
974
  () => wire({
975
+ referral_code: optionalText(),
870
976
  referrals: nullableList(referralSchema()),
871
- completed_count: count2(),
872
- total_earned: majorUnits(),
873
- pagination: z.optional(
874
- wire({
875
- page: count2(),
876
- page_size: count2(),
877
- total_items: count2(),
878
- total_pages: count2()
879
- })
880
- )
977
+ pagination: z.optional(wire({ page: count2(), limit: count2(), total_items: count2() }))
881
978
  })
882
979
  );
883
- var registeredSchema = /* @__PURE__ */ lazy(
884
- () => z.pipe(
885
- wire({
886
- id: z.string(),
887
- referral_code: z._default(z.string(), ""),
888
- status: status(),
889
- referee_bonus: z._default(majorUnits(), 0),
890
- created_at: optionalTimestamp()
891
- }),
892
- z.transform(
893
- (r) => ({
894
- id: r.id,
895
- code: r.referralCode,
896
- status: r.status,
897
- refereeBonus: r.refereeBonus,
898
- createdAt: r.createdAt
899
- })
900
- )
901
- )
902
- );
903
980
  var positiveInt = (value, fallback) => typeof value === "number" && Number.isSafeInteger(value) && value >= 1 ? value : fallback;
904
- function registerInputProblem(input) {
905
- if (typeof input !== "object" || input === null || Array.isArray(input))
906
- return "referrals.register: input must be an object { code }.";
907
- const { code } = input;
908
- if (typeof code !== "string" || code.trim() === "") return "referrals.register: code must be non-empty text.";
909
- return void 0;
910
- }
981
+ var reportedTotal = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : 0;
911
982
  function createReferralsApi(transport) {
912
983
  return {
913
984
  get: (_params, options) => transport.request({ method: "GET", path: "/referrals", auth: "required", schema: infoSchema(), options }),
@@ -923,12 +994,11 @@ function createReferralsApi(transport) {
923
994
  auth: "required",
924
995
  schema: historySchema(),
925
996
  options
926
- }).then(({ referrals, completedCount, totalEarned, pagination }) => {
927
- const items = historyItems(referrals);
928
- const received = Array.isArray(referrals) ? referrals.length : 0;
997
+ }).then(({ referralCode, referrals, pagination }) => {
998
+ const items = Array.isArray(referrals) ? referrals : [];
929
999
  const page = positiveInt(pagination?.page, requestedPage ?? 1);
930
- const perPage = positiveInt(pagination?.pageSize, requestedPerPage ?? DEFAULT_PER_PAGE);
931
- 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;
932
1002
  const totalItems = Math.max(reportedTotal(pagination?.totalItems), seen);
933
1003
  return {
934
1004
  items,
@@ -936,21 +1006,9 @@ function createReferralsApi(transport) {
936
1006
  perPage,
937
1007
  totalItems,
938
1008
  totalPages: totalItems > 0 ? Math.ceil(totalItems / perPage) : 0,
939
- completedCount,
940
- totalEarned
1009
+ code: referralCode
941
1010
  };
942
1011
  });
943
- },
944
- register: (input, options) => {
945
- const problem = registerInputProblem(input);
946
- if (problem !== void 0) return rejectInput(transport, problem, REGISTER_ROUTE);
947
- return transport.request({
948
- ...REGISTER_ROUTE,
949
- body: { referral_code: input.code.trim() },
950
- auth: "required",
951
- schema: registeredSchema(),
952
- options
953
- });
954
1012
  }
955
1013
  };
956
1014
  }