@masterunoco/casinowebengine-api 0.1.5 → 0.1.7

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
@@ -333,6 +333,7 @@ var JwtAuth = class {
333
333
  const payload = { username, password, recaptchaToken };
334
334
  const res = await this.client.post("/auth/login", payload, authPolicy);
335
335
  this.setUser(res.user, res.token);
336
+ storage.setSocketToken(res.socketToken);
336
337
  return res;
337
338
  }
338
339
  async GoogleLogin(data) {
@@ -497,6 +498,9 @@ var ContentAPI = class {
497
498
  get(slug) {
498
499
  return this.http.get(`/content-pages/${slug}`, "none");
499
500
  }
501
+ getAnnouncements() {
502
+ return this.http.get("/announcements", "none");
503
+ }
500
504
  };
501
505
 
502
506
  // src/apis/deposit.ts
@@ -522,7 +526,7 @@ var GamesAPI = class {
522
526
  }
523
527
  /** Public: search games */
524
528
  search(request) {
525
- return this.http.post("/games/search", request, "none");
529
+ return this.http.get(`/games/search?${new URLSearchParams(request).toString()}`, "none");
526
530
  }
527
531
  getCategories() {
528
532
  return this.http.get("/games/categories", "none");
@@ -532,8 +536,8 @@ var GamesAPI = class {
532
536
  return this.http.post(`/games/getLink`, { gameId }, "required");
533
537
  }
534
538
  /** Public: demo link */
535
- getDemoLink(gameId) {
536
- return this.http.post("/games/getDemoLink", { gameId }, "none");
539
+ getDemoLink(gameExternalId) {
540
+ return this.http.post("/games/getDemoLink", { gameExternalId }, "none");
537
541
  }
538
542
  setFavorite(gameId, isFavorite) {
539
543
  return this.http.post("/games/favorites", { gameId, isFavorite }, "required");
@@ -562,6 +566,9 @@ var GamesAPI = class {
562
566
  getProviders() {
563
567
  return this.http.get("/games/providers", "none");
564
568
  }
569
+ getCategoriesProviders() {
570
+ return this.http.get("/games/providers/categories", "none");
571
+ }
565
572
  getLobby() {
566
573
  const geo = new GeolocationAPI(this.http);
567
574
  const countryCode = geo.getCountryCode();
@@ -571,6 +578,9 @@ var GamesAPI = class {
571
578
  }
572
579
  return this.http.get(url, "none");
573
580
  }
581
+ getGameOfTheWeek() {
582
+ return this.http.get("/games/game-of-the-week", "none");
583
+ }
574
584
  };
575
585
 
576
586
  // src/apis/luckyWheel.ts
@@ -650,6 +660,12 @@ var PlayerAPI = class {
650
660
  verifyPhoneCode(data) {
651
661
  return this.http.post("/verify/phone/confirm", data);
652
662
  }
663
+ verifyPhoneSignup(data) {
664
+ return this.http.post("/verify/phone/send", data);
665
+ }
666
+ verifyPhoneCodeSignup(data) {
667
+ return this.http.post("/verify/phone/confirm", data);
668
+ }
653
669
  getVerificationStatus() {
654
670
  return this.http.get("/player/verification-status");
655
671
  }
@@ -771,6 +787,9 @@ var SettingsAPI = class {
771
787
  getCurrencies() {
772
788
  return this.http.get("/currencies/get", "none");
773
789
  }
790
+ getCurrenciesRates() {
791
+ return this.http.get("/currencies/rates", "none");
792
+ }
774
793
  getWebSetting(lang) {
775
794
  return this.http.get(`/website-settings?language=${lang}&key[]=footerCasinoItems&key[]=footerSportsItems&key[]=footerSocialMedia&key[]=footerPromoItems&key[]=footerSupportLegalItems&key[]=footerAboutUsItems&key[]=footerAppLinks`, "none");
776
795
  }
@@ -804,6 +823,12 @@ var SettingsAPI = class {
804
823
  getSupportEmail(lang) {
805
824
  return this.http.get(`/website-settings?language=${lang}&key[]=supportEmail`, "none");
806
825
  }
826
+ getReferralBannersPack(lang) {
827
+ return this.http.get(`/website-settings?language=${lang}&key[]=referral_banners`, "none");
828
+ }
829
+ getReferralGraphicsPack(lang) {
830
+ return this.http.get(`/website-settings?language=${lang}&key[]=Referral_graphics`, "none");
831
+ }
807
832
  };
808
833
 
809
834
  // src/apis/sport.ts
@@ -855,6 +880,171 @@ var WithdrawAPI = class {
855
880
  }
856
881
  };
857
882
 
883
+ // src/ws/socketClient.ts
884
+ var SocketClient = class {
885
+ constructor(opts) {
886
+ this.opts = opts;
887
+ this.ws = null;
888
+ this.status = "idle";
889
+ this.pingTimer = null;
890
+ this.reconnectTimer = null;
891
+ this.reconnectAttempt = 0;
892
+ this.manualClose = false;
893
+ this.hasJoinedAfterLogin = false;
894
+ this.handlers = /* @__PURE__ */ new Map();
895
+ }
896
+ /** Current status useful for UI */
897
+ getStatus() {
898
+ return this.status;
899
+ }
900
+ /** Raw socket access (optional) */
901
+ getSocket() {
902
+ return this.ws;
903
+ }
904
+ /** Connect (idempotent) */
905
+ connect() {
906
+ if (this.ws && (this.ws.readyState === WebSocket.OPEN || this.ws.readyState === WebSocket.CONNECTING)) {
907
+ return;
908
+ }
909
+ this.manualClose = false;
910
+ this.setStatus(this.reconnectAttempt > 0 ? "reconnecting" : "connecting");
911
+ this.ws = new WebSocket(this.opts.url);
912
+ this.ws.onopen = () => {
913
+ this.reconnectAttempt = 0;
914
+ this.setStatus("connected");
915
+ this.sendRaw({
916
+ type: "joinPublic",
917
+ payload: { name: this.opts.publicName ?? "player1" }
918
+ });
919
+ this.startPing();
920
+ this.tryJoinAfterLogin();
921
+ };
922
+ this.ws.onmessage = (event) => {
923
+ let parsed;
924
+ try {
925
+ parsed = JSON.parse(event.data);
926
+ } catch {
927
+ this.emit("*", event.data, { type: "*", message: event.data });
928
+ return;
929
+ }
930
+ const data = parsed.message ?? parsed.payload ?? parsed;
931
+ this.emit(parsed.type, data, parsed);
932
+ this.emit("*", data, parsed);
933
+ };
934
+ this.ws.onerror = () => {
935
+ this.emit("error", null, { type: "error" });
936
+ };
937
+ this.ws.onclose = () => {
938
+ this.stopPing();
939
+ this.setStatus("disconnected");
940
+ if (!this.manualClose && (this.opts.autoReconnect ?? true)) {
941
+ this.scheduleReconnect();
942
+ }
943
+ };
944
+ }
945
+ /** Disconnect gracefully */
946
+ disconnect(code = 1e3, reason = "client_disconnect") {
947
+ this.manualClose = true;
948
+ this.stopPing();
949
+ this.clearReconnect();
950
+ if (this.ws) {
951
+ try {
952
+ this.ws.close(code, reason);
953
+ } catch {
954
+ }
955
+ }
956
+ this.ws = null;
957
+ this.setStatus("disconnected");
958
+ }
959
+ /** Call after login (or whenever token/user changes) */
960
+ onLogin() {
961
+ this.hasJoinedAfterLogin = false;
962
+ this.tryJoinAfterLogin();
963
+ }
964
+ /** Reset join flag (call on logout) */
965
+ onLogout() {
966
+ this.hasJoinedAfterLogin = false;
967
+ }
968
+ /** Subscribe to message type (e.g. 'happyHourStarted', 'latest-bet'). Use '*' to receive everything. */
969
+ on(type, handler) {
970
+ const set = this.handlers.get(type) ?? /* @__PURE__ */ new Set();
971
+ set.add(handler);
972
+ this.handlers.set(type, set);
973
+ return () => this.off(type, handler);
974
+ }
975
+ off(type, handler) {
976
+ const set = this.handlers.get(type);
977
+ if (!set) return;
978
+ set.delete(handler);
979
+ if (set.size === 0) this.handlers.delete(type);
980
+ }
981
+ /** Send a typed message (SDK-side helper) */
982
+ send(type, payload) {
983
+ this.sendRaw({ type, payload });
984
+ }
985
+ // ----------------- internals -----------------
986
+ emit(type, data, raw) {
987
+ const set = this.handlers.get(type);
988
+ if (!set) return;
989
+ for (const fn of set) {
990
+ try {
991
+ fn(data, raw);
992
+ } catch {
993
+ }
994
+ }
995
+ }
996
+ sendRaw(msg) {
997
+ if (!this.ws || this.ws.readyState !== WebSocket.OPEN) return;
998
+ this.ws.send(JSON.stringify(msg));
999
+ }
1000
+ tryJoinAfterLogin() {
1001
+ if (this.hasJoinedAfterLogin) return;
1002
+ if (!this.ws || this.ws.readyState !== WebSocket.OPEN) return;
1003
+ const user = this.opts.getUser?.() ?? null;
1004
+ if (!user?.id) return;
1005
+ const socketToken = this.opts.getSocketToken?.() ?? "";
1006
+ if (!socketToken) return;
1007
+ this.sendRaw({
1008
+ type: "join",
1009
+ payload: {
1010
+ name: user.name || "player1",
1011
+ playerId: user.id,
1012
+ socketToken
1013
+ }
1014
+ });
1015
+ this.hasJoinedAfterLogin = true;
1016
+ }
1017
+ startPing() {
1018
+ this.stopPing();
1019
+ const every = this.opts.pingIntervalMs ?? 5e3;
1020
+ this.pingTimer = setInterval(() => {
1021
+ if (!this.ws || this.ws.readyState !== WebSocket.OPEN) return;
1022
+ this.sendRaw({ type: "ping", payload: { ping: 1 } });
1023
+ }, every);
1024
+ }
1025
+ stopPing() {
1026
+ if (this.pingTimer) clearInterval(this.pingTimer);
1027
+ this.pingTimer = null;
1028
+ }
1029
+ scheduleReconnect() {
1030
+ this.clearReconnect();
1031
+ this.reconnectAttempt += 1;
1032
+ const base = Math.min(1e3 * 2 ** (this.reconnectAttempt - 1), this.opts.maxReconnectDelayMs ?? 3e4);
1033
+ const jitter = Math.floor(Math.random() * 250);
1034
+ this.reconnectTimer = setTimeout(() => {
1035
+ this.connect();
1036
+ }, base + jitter);
1037
+ }
1038
+ clearReconnect() {
1039
+ if (this.reconnectTimer) clearTimeout(this.reconnectTimer);
1040
+ this.reconnectTimer = null;
1041
+ }
1042
+ setStatus(s) {
1043
+ this.status = s;
1044
+ this.emit("status", s, { type: "status", payload: s });
1045
+ }
1046
+ };
1047
+
858
1048
  // src/sdk.ts
859
1049
  var GameSDK = class {
860
1050
  constructor(cfg) {
@@ -864,6 +1054,12 @@ var GameSDK = class {
864
1054
  // <-- uses this.auth (defined below)
865
1055
  timeoutMs: cfg.timeoutMs ?? 15e3
866
1056
  });
1057
+ this.ws = new SocketClient({
1058
+ url: cfg.socketUrl || "",
1059
+ publicName: "player1",
1060
+ getSocketToken: cfg.getSocketToken ?? (() => storage.getSocketToken()),
1061
+ getUser: () => this.auth.getUser() ? { id: this.auth.getUser().id, name: this.auth.getUser().name } : null
1062
+ });
867
1063
  this.auth = new JwtAuth(this.http);
868
1064
  this.affiliate = new AffiliateAPI(this.http);
869
1065
  this.content = new ContentAPI(this.http);