@getenginex/sdk-igaming 0.11.0 → 0.12.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,8 +1,8 @@
1
- import { createClubApi, LOCALE, rejectInput, pageInputProblem, nonNegativeMinorUnits, optionalTimestamp, nullableList, protoEnum, optionalText, currencyOrEmpty, minorUnits, integerText, list, text, count, durationSeconds } from './chunk-LMBQDSFV.js';
2
- export { keepsClubIdempotencyKey } from './chunk-LMBQDSFV.js';
1
+ import { createClubApi, LOCALE, rejectInput, pageInputProblem, nonNegativeMinorUnits, optionalTimestamp, nullableList, protoEnum, optionalText, nonNegativeInteger, minorUnits, integerText, flagOrNull, list, currencyOrEmpty, minorUnitsText, text, count, durationSeconds } from './chunk-5ERRD3OA.js';
2
+ export { keepsClubIdempotencyKey } from './chunk-5ERRD3OA.js';
3
3
  import { EnginexError } from '@getenginex/sdk';
4
4
  import * as extension from '@getenginex/sdk/extension';
5
- import { lazy, wire, decimalPlaces, currencyCode, money as money$1 } from '@getenginex/sdk/extension';
5
+ import { lazy, wire, decimalPlaces, currencyCode, money as money$1, strictValue } from '@getenginex/sdk/extension';
6
6
  import * as z2 from 'zod/mini';
7
7
 
8
8
  var betFields = () => ({
@@ -894,45 +894,110 @@ var tierBenefits = () => z2.pipe(
894
894
  return z2.NEVER;
895
895
  })
896
896
  );
897
+ var optionalFlag = () => z2.nullish(z2.boolean());
898
+ var countOrNull = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : null;
899
+ var currencyOrNull = () => z2.pipe(
900
+ z2.nullish(currencyOrEmpty()),
901
+ z2.transform((value) => value == null || value === "" ? null : value)
902
+ );
903
+ var ISO_CURRENCY = /^[A-Z]{3}$/;
904
+ var pendingCurrency = () => z2.pipe(
905
+ z2.nullish(
906
+ z2.string().check(z2.refine((value) => value === "" || ISO_CURRENCY.test(value), "Expected a currency code"))
907
+ ),
908
+ z2.transform((value) => value == null || value === "" ? null : value)
909
+ );
910
+ var pendingSchema = () => wire({
911
+ idempotency_key: optionalText(),
912
+ points: nonNegativeInteger(),
913
+ currency: pendingCurrency()
914
+ });
915
+ function pendingOrNull(value) {
916
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
917
+ const { idempotencyKey, points, currency } = value;
918
+ if (idempotencyKey !== null && typeof idempotencyKey !== "string") return null;
919
+ const count3 = countOrNull(points);
920
+ if (count3 === null) return null;
921
+ const code = typeof currency === "string" && ISO_CURRENCY.test(currency) ? currency : null;
922
+ return { idempotencyKey, points: count3, currency: code };
923
+ }
897
924
  var loyaltySchema = /* @__PURE__ */ lazy(
898
925
  () => z2.pipe(
899
926
  wire({
900
- total_points_earned: integerText(),
901
- current_points: integerText(),
902
- points_redeemed: integerText(),
927
+ // Counters: the gateway always writes them; absent (an answer with only `available: false`) is `0`, never
928
+ // `undefined`.
929
+ total_points_earned: z2._default(integerText(), 0),
930
+ current_points: z2._default(integerText(), 0),
931
+ points_redeemed: z2._default(integerText(), 0),
903
932
  current_tier: optionalText(),
904
- tier_points: integerText(),
933
+ tier_points: z2._default(integerText(), 0),
905
934
  lifetime_wagered: z2._default(minorUnits(), 0),
906
935
  lifetime_deposited: z2._default(minorUnits(), 0),
907
936
  tier_benefits_json: tierBenefits(),
908
- tier_expires_at: optionalTimestamp()
937
+ tier_expires_at: optionalTimestamp(),
938
+ available: optionalFlag(),
939
+ program_active: optionalFlag(),
940
+ history_available: optionalFlag(),
941
+ can_redeem: optionalFlag(),
942
+ min_redemption: z2.nullish(nonNegativeInteger()),
943
+ // A rate, not an amount to show: a malformed one (a negative, a fraction, ≥ 2^53) follows the normal rule
944
+ // and, in `'warn'`, becomes `null`, so the page still renders and only the redemption is unavailable.
945
+ point_value_cents: z2.nullish(nonNegativeInteger()),
946
+ redemption_currency: currencyOrNull(),
947
+ redemption_decimal_places: z2.nullish(decimalPlaces()),
948
+ pending_redemption: z2.nullish(pendingSchema())
909
949
  }),
910
- z2.transform(({ tierBenefitsJson, ...rest }) => {
911
- const benefits = tierBenefitsJson instanceof ParsedBenefits ? tierBenefitsJson.value : null;
912
- return { ...rest, tierBenefits: benefits };
950
+ z2.transform((data) => {
951
+ const benefits = data.tierBenefitsJson instanceof ParsedBenefits ? data.tierBenefitsJson.value : null;
952
+ return {
953
+ totalPointsEarned: data.totalPointsEarned,
954
+ currentPoints: data.currentPoints,
955
+ pointsRedeemed: data.pointsRedeemed,
956
+ currentTier: data.currentTier,
957
+ tierPoints: data.tierPoints,
958
+ lifetimeWagered: data.lifetimeWagered,
959
+ lifetimeDeposited: data.lifetimeDeposited,
960
+ tierBenefits: benefits,
961
+ tierExpiresAt: data.tierExpiresAt,
962
+ available: flagOrNull(data.available),
963
+ programActive: flagOrNull(data.programActive),
964
+ historyAvailable: flagOrNull(data.historyAvailable),
965
+ canRedeem: flagOrNull(data.canRedeem),
966
+ minRedemption: countOrNull(data.minRedemption),
967
+ pointValue: countOrNull(data.pointValueCents),
968
+ redemptionCurrency: data.redemptionCurrency,
969
+ redemptionDecimalPlaces: data.redemptionDecimalPlaces ?? null,
970
+ pendingRedemption: pendingOrNull(data.pendingRedemption)
971
+ };
913
972
  })
914
973
  )
915
974
  );
975
+ var VALUE_MISMATCH = "Expected value and value_minor to carry the same amount";
976
+ var redeemWire = () => wire({
977
+ success: z2.optional(z2.boolean()),
978
+ message: z2.optional(z2.string()),
979
+ redeemed_points: integerText(),
980
+ value: z2.nullish(nonNegativeMinorUnits()),
981
+ value_minor: z2.nullish(minorUnitsText()),
982
+ // Currency strict even in `'warn'`; absent, `null` and `''` still become `null`.
983
+ currency: currencyOrNull(),
984
+ currency_decimal_places: z2.nullish(decimalPlaces()),
985
+ bonus_id: optionalText()
986
+ });
987
+ var sameAmount = () => strictValue((v) => {
988
+ const { value, valueMinor } = v;
989
+ return value == null || valueMinor == null || value === valueMinor;
990
+ }, VALUE_MISMATCH);
916
991
  var redeemSchema = /* @__PURE__ */ lazy(
917
992
  () => z2.pipe(
918
- wire({
919
- success: z2.optional(z2.boolean()),
920
- message: z2.optional(z2.string()),
921
- redeemed_points: integerText(),
922
- value: z2.nullish(minorUnits()),
923
- // Currency strict even in `'warn'`; absent, `null` and `''` still become `null`.
924
- currency: z2.pipe(
925
- z2.nullish(currencyOrEmpty()),
926
- z2.transform((value) => value == null || value === "" ? null : value)
927
- ),
928
- bonus_id: optionalText()
929
- }),
993
+ z2.pipe(redeemWire(), sameAmount()),
930
994
  z2.transform((data) => ({
931
995
  success: data.success,
932
996
  message: data.message,
933
997
  redeemedPoints: data.redeemedPoints,
934
- value: data.value ?? null,
998
+ value: data.valueMinor ?? data.value ?? null,
935
999
  currency: data.currency,
1000
+ currencyDecimalPlaces: data.currencyDecimalPlaces ?? null,
936
1001
  bonusId: data.bonusId
937
1002
  }))
938
1003
  )
@@ -1001,28 +1066,73 @@ var missionSchema = /* @__PURE__ */ lazy(
1001
1066
  valid_to: optionalTimestamp()
1002
1067
  })
1003
1068
  );
1069
+ var userMissionFields = () => ({
1070
+ id: z2.string(),
1071
+ mission_id: z2.string(),
1072
+ mission_name: z2._default(z2.string(), ""),
1073
+ current_progress: integerText(),
1074
+ target_value: integerText(),
1075
+ progress_percentage: z2.number(),
1076
+ status: openUnion(USER_MISSION_STATUSES),
1077
+ reward_type: openUnion(REWARD_TYPES),
1078
+ reward_value: minorUnits(),
1079
+ period_end: optionalTimestamp(),
1080
+ completed_at: optionalTimestamp()
1081
+ });
1004
1082
  var userMissionsSchema = /* @__PURE__ */ lazy(
1083
+ () => z2.pipe(
1084
+ wire({ missions: nullableList(wire(userMissionFields())) }),
1085
+ z2.transform((data) => data.missions)
1086
+ )
1087
+ );
1088
+ var historyMissionSchema = () => z2.pipe(
1089
+ wire({
1090
+ ...userMissionFields(),
1091
+ claimed_at: optionalTimestamp(),
1092
+ offer_active: z2.nullish(z2.boolean()),
1093
+ description: optionalText(),
1094
+ mission_type: z2.nullish(openUnion(MISSION_TYPES)),
1095
+ objective_type: z2.nullish(openUnion(OBJECTIVE_TYPES)),
1096
+ target_game_category: optionalText()
1097
+ }),
1098
+ // In `'warn'` a divergent `offer_active` arrives raw: the SDK delivers `null`, never the text `"false"`.
1099
+ z2.transform(
1100
+ (m) => ({
1101
+ ...m,
1102
+ offerActive: flagOrNull(m.offerActive),
1103
+ missionType: m.missionType ?? null,
1104
+ objectiveType: m.objectiveType ?? null
1105
+ })
1106
+ )
1107
+ );
1108
+ var myMissionsSchema = /* @__PURE__ */ lazy(
1005
1109
  () => z2.pipe(
1006
1110
  wire({
1007
- missions: nullableList(
1008
- wire({
1009
- id: z2.string(),
1010
- mission_id: z2.string(),
1011
- mission_name: z2._default(z2.string(), ""),
1012
- current_progress: integerText(),
1013
- target_value: integerText(),
1014
- progress_percentage: z2.number(),
1015
- status: openUnion(USER_MISSION_STATUSES),
1016
- reward_type: openUnion(REWARD_TYPES),
1017
- reward_value: minorUnits(),
1018
- period_end: optionalTimestamp(),
1019
- completed_at: optionalTimestamp()
1020
- })
1021
- )
1111
+ missions: nullableList(historyMissionSchema()),
1112
+ available: z2.nullish(z2.boolean()),
1113
+ offers_available: z2.nullish(z2.boolean()),
1114
+ history_available: z2.nullish(z2.boolean())
1022
1115
  }),
1023
- z2.transform((data) => data.missions)
1116
+ z2.transform(
1117
+ (data) => ({
1118
+ missions: data.missions,
1119
+ available: flagOrNull(data.available),
1120
+ offersAvailable: flagOrNull(data.offersAvailable),
1121
+ historyAvailable: flagOrNull(data.historyAvailable)
1122
+ })
1123
+ )
1024
1124
  )
1025
1125
  );
1126
+ var MY_MISSIONS_ROUTE = { method: "GET", path: "/my/missions" };
1127
+ function getMineInputProblem(input) {
1128
+ if (input === void 0) return void 0;
1129
+ if (typeof input !== "object" || input === null || Array.isArray(input))
1130
+ return "missions.getMine: input must be an object { includeHistory? }.";
1131
+ const { includeHistory } = input;
1132
+ if (includeHistory !== void 0 && typeof includeHistory !== "boolean")
1133
+ return "missions.getMine: includeHistory must be a boolean.";
1134
+ return void 0;
1135
+ }
1026
1136
  function createMissionsApi(transport) {
1027
1137
  return {
1028
1138
  list: (input, options) => {
@@ -1039,13 +1149,19 @@ function createMissionsApi(transport) {
1039
1149
  options
1040
1150
  });
1041
1151
  },
1042
- listMine: (_params, options) => transport.request({
1043
- method: "GET",
1044
- path: "/my/missions",
1045
- auth: "required",
1046
- schema: userMissionsSchema(),
1047
- options
1048
- })
1152
+ listMine: (_params, options) => transport.request({ ...MY_MISSIONS_ROUTE, auth: "required", schema: userMissionsSchema(), options }),
1153
+ getMine: (input, options) => {
1154
+ const problem = getMineInputProblem(input);
1155
+ if (problem !== void 0) return rejectInput(transport, problem, MY_MISSIONS_ROUTE);
1156
+ return transport.request({
1157
+ ...MY_MISSIONS_ROUTE,
1158
+ // The gateway only honors the literal `true`; `false` sends nothing (the same request as `listMine`).
1159
+ query: input?.includeHistory === true ? { include_history: "true" } : void 0,
1160
+ auth: "required",
1161
+ schema: myMissionsSchema(),
1162
+ options
1163
+ });
1164
+ }
1049
1165
  };
1050
1166
  }
1051
1167
  var DEFAULT_PER_PAGE = 20;