@wowlabtech/mini-app-adapter 0.2.7 → 0.2.8

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.cjs CHANGED
@@ -666,6 +666,9 @@ var BaseMiniAppAdapter = class {
666
666
  getLaunchParams() {
667
667
  return void 0;
668
668
  }
669
+ getCustomLaunchParams() {
670
+ return { customLaunchParams: {} };
671
+ }
669
672
  decodeStartParam(_param) {
670
673
  return void 0;
671
674
  }
@@ -1449,6 +1452,24 @@ var TelegramMiniAppAdapter = class extends BaseMiniAppAdapter {
1449
1452
  return void 0;
1450
1453
  }
1451
1454
  }
1455
+ getCustomLaunchParams() {
1456
+ const customFromUrl = this.readCustomUrlParams((key) => key.toLowerCase().startsWith("tgwebapp"));
1457
+ let customFromStartParam = {};
1458
+ try {
1459
+ const launchParams = (0, import_sdk_react.retrieveLaunchParams)();
1460
+ const startParam = launchParams.tgWebAppStartParam;
1461
+ if (typeof startParam === "string" && startParam) {
1462
+ customFromStartParam = this.normalizeDecodedStartParam(startParam);
1463
+ }
1464
+ } catch {
1465
+ }
1466
+ return {
1467
+ customLaunchParams: {
1468
+ ...customFromUrl,
1469
+ ...customFromStartParam
1470
+ }
1471
+ };
1472
+ }
1452
1473
  decodeStartParam(param) {
1453
1474
  try {
1454
1475
  return (0, import_sdk.decodeStartParam)(param);
@@ -1795,6 +1816,70 @@ var TelegramMiniAppAdapter = class extends BaseMiniAppAdapter {
1795
1816
  }
1796
1817
  }
1797
1818
  }
1819
+ normalizeDecodedStartParam(startParam) {
1820
+ let decoded;
1821
+ try {
1822
+ decoded = (0, import_sdk.decodeStartParam)(startParam);
1823
+ } catch {
1824
+ decoded = startParam;
1825
+ }
1826
+ if (decoded && typeof decoded === "object" && !Array.isArray(decoded)) {
1827
+ return { ...decoded };
1828
+ }
1829
+ if (typeof decoded === "string" && decoded) {
1830
+ const parsed = this.parseQueryString(decoded);
1831
+ if (Object.keys(parsed).length) {
1832
+ return parsed;
1833
+ }
1834
+ return { startParam: decoded };
1835
+ }
1836
+ return {};
1837
+ }
1838
+ readCustomUrlParams(isServiceParam) {
1839
+ if (typeof window === "undefined") {
1840
+ return {};
1841
+ }
1842
+ const result = {};
1843
+ const append = (source) => {
1844
+ const keys = /* @__PURE__ */ new Set();
1845
+ for (const [key] of source.entries()) {
1846
+ keys.add(key);
1847
+ }
1848
+ for (const key of keys) {
1849
+ if (isServiceParam(key)) {
1850
+ continue;
1851
+ }
1852
+ const values = source.getAll(key);
1853
+ if (!values.length) {
1854
+ continue;
1855
+ }
1856
+ result[key] = values.length === 1 ? values[0] : values;
1857
+ }
1858
+ };
1859
+ append(new URLSearchParams(window.location.search));
1860
+ const hash = window.location.hash.startsWith("#") ? window.location.hash.slice(1) : window.location.hash;
1861
+ if (hash && hash.includes("=")) {
1862
+ append(new URLSearchParams(hash));
1863
+ }
1864
+ return result;
1865
+ }
1866
+ parseQueryString(value) {
1867
+ const normalized = value.startsWith("?") ? value.slice(1) : value;
1868
+ const params = new URLSearchParams(normalized);
1869
+ const result = {};
1870
+ const keys = /* @__PURE__ */ new Set();
1871
+ for (const [key] of params.entries()) {
1872
+ keys.add(key);
1873
+ }
1874
+ for (const key of keys) {
1875
+ const values = params.getAll(key);
1876
+ if (!values.length) {
1877
+ continue;
1878
+ }
1879
+ result[key] = values.length === 1 ? values[0] : values;
1880
+ }
1881
+ return result;
1882
+ }
1798
1883
  notifyViewRestore() {
1799
1884
  for (const listener of this.viewRestoreListeners) {
1800
1885
  try {
@@ -1965,6 +2050,11 @@ var VKMiniAppAdapter = class extends BaseMiniAppAdapter {
1965
2050
  queryParams: this.queryParams
1966
2051
  };
1967
2052
  }
2053
+ getCustomLaunchParams() {
2054
+ return {
2055
+ customLaunchParams: this.readCustomUrlParams()
2056
+ };
2057
+ }
1968
2058
  async openExternalLink(url) {
1969
2059
  const a = document.createElement("a");
1970
2060
  a.href = url;
@@ -1975,6 +2065,38 @@ var VKMiniAppAdapter = class extends BaseMiniAppAdapter {
1975
2065
  a.click();
1976
2066
  a.remove();
1977
2067
  }
2068
+ readCustomUrlParams() {
2069
+ if (typeof window === "undefined") {
2070
+ return {};
2071
+ }
2072
+ const result = {};
2073
+ const isServiceParam = (key) => {
2074
+ const normalized = key.toLowerCase();
2075
+ return normalized.startsWith("vk_") || normalized === "sign";
2076
+ };
2077
+ const append = (source) => {
2078
+ const keys = /* @__PURE__ */ new Set();
2079
+ for (const [key] of source.entries()) {
2080
+ keys.add(key);
2081
+ }
2082
+ for (const key of keys) {
2083
+ if (isServiceParam(key)) {
2084
+ continue;
2085
+ }
2086
+ const values = source.getAll(key);
2087
+ if (!values.length) {
2088
+ continue;
2089
+ }
2090
+ result[key] = values.length === 1 ? values[0] : values;
2091
+ }
2092
+ };
2093
+ append(new URLSearchParams(window.location.search));
2094
+ const hash = window.location.hash.startsWith("#") ? window.location.hash.slice(1) : window.location.hash;
2095
+ if (hash && hash.includes("=")) {
2096
+ append(new URLSearchParams(hash));
2097
+ }
2098
+ return result;
2099
+ }
1978
2100
  async supports(capability) {
1979
2101
  switch (capability) {
1980
2102
  case "haptics": {