@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.d.cts CHANGED
@@ -60,6 +60,9 @@ interface MiniAppViewportState {
60
60
  height: number;
61
61
  stableHeight: number;
62
62
  }
63
+ interface MiniAppCustomLaunchParams {
64
+ customLaunchParams: Record<string, unknown>;
65
+ }
63
66
  interface MiniAppInitOptions {
64
67
  /**
65
68
  * Enables verbose logs for platforms that support it.
@@ -198,6 +201,10 @@ interface MiniAppAdapter {
198
201
  * Reads platform launch parameters, if available.
199
202
  */
200
203
  getLaunchParams?(): unknown;
204
+ /**
205
+ * Returns custom launch parameters that are not part of platform service fields.
206
+ */
207
+ getCustomLaunchParams(): MiniAppCustomLaunchParams;
201
208
  /**
202
209
  * Decodes platform specific start parameter.
203
210
  */
@@ -345,6 +352,7 @@ declare abstract class BaseMiniAppAdapter implements MiniAppAdapter {
345
352
  onAppearanceChange(callback: (appearance: 'dark' | 'light' | undefined) => void): () => void;
346
353
  getInitData(): string | undefined;
347
354
  getLaunchParams(): unknown;
355
+ getCustomLaunchParams(): MiniAppCustomLaunchParams;
348
356
  decodeStartParam(_param: string): unknown;
349
357
  requestFullscreen(): void;
350
358
  onViewportChange(callback: (state: {
@@ -444,6 +452,7 @@ declare class TelegramMiniAppAdapter extends BaseMiniAppAdapter {
444
452
  closeApp(): Promise<void>;
445
453
  getInitData(): string | undefined;
446
454
  getLaunchParams(): unknown;
455
+ getCustomLaunchParams(): MiniAppCustomLaunchParams;
447
456
  decodeStartParam(param: string): unknown;
448
457
  requestFullscreen(): void;
449
458
  getViewportInsets(): MiniAppViewportInsets | undefined;
@@ -472,6 +481,9 @@ declare class TelegramMiniAppAdapter extends BaseMiniAppAdapter {
472
481
  private safeHeightFromSdk;
473
482
  private stableHeightFromSdk;
474
483
  private notifyViewHide;
484
+ private normalizeDecodedStartParam;
485
+ private readCustomUrlParams;
486
+ private parseQueryString;
475
487
  private notifyViewRestore;
476
488
  protected onDestroy(): void;
477
489
  }
@@ -498,7 +510,9 @@ declare class VKMiniAppAdapter extends BaseMiniAppAdapter {
498
510
  }): Promise<void>;
499
511
  getEnvironment(): MiniAppEnvironmentInfo;
500
512
  getLaunchParams(): unknown;
513
+ getCustomLaunchParams(): MiniAppCustomLaunchParams;
501
514
  openExternalLink(url: string): Promise<void>;
515
+ private readCustomUrlParams;
502
516
  supports(capability: MiniAppCapability): Promise<boolean>;
503
517
  requestPhone(): Promise<string | null>;
504
518
  requestNotificationsPermission(): Promise<boolean>;
@@ -589,4 +603,4 @@ declare function trackPixelEvent(event: string, payload?: Record<string, unknown
589
603
 
590
604
  declare function getPlatform(): MiniAppPlatform;
591
605
 
592
- export { AdapterProvider, BaseMiniAppAdapter, type CreateAdapterOptions, MaxMiniAppAdapter, type MiniAppAdapter, type MiniAppCapability, type MiniAppEnvironmentInfo, type MiniAppInitOptions, type MiniAppPlatform, type MiniAppPopupOptions, type MiniAppQrScanOptions, type MiniAppShareStoryOptions, type MiniAppViewportState, ShellMiniAppAdapter, TelegramMiniAppAdapter, VKMiniAppAdapter, WebMiniAppAdapter, configureVkPixel, createAdapter, createShellAPI, detectPlatform, getActiveAdapter, getPlatform, isShell, isShellAndroid, isShellIOS, readShellPlatform, requestShellPushPermission, shell, storeShellToken, trackConversionEvent, trackPixelEvent, useAdapterTheme, useMiniAppAdapter, useSafeArea };
606
+ export { AdapterProvider, BaseMiniAppAdapter, type CreateAdapterOptions, MaxMiniAppAdapter, type MiniAppAdapter, type MiniAppCapability, type MiniAppCustomLaunchParams, type MiniAppEnvironmentInfo, type MiniAppInitOptions, type MiniAppPlatform, type MiniAppPopupOptions, type MiniAppQrScanOptions, type MiniAppShareStoryOptions, type MiniAppViewportState, ShellMiniAppAdapter, TelegramMiniAppAdapter, VKMiniAppAdapter, WebMiniAppAdapter, configureVkPixel, createAdapter, createShellAPI, detectPlatform, getActiveAdapter, getPlatform, isShell, isShellAndroid, isShellIOS, readShellPlatform, requestShellPushPermission, shell, storeShellToken, trackConversionEvent, trackPixelEvent, useAdapterTheme, useMiniAppAdapter, useSafeArea };
package/dist/index.d.ts CHANGED
@@ -60,6 +60,9 @@ interface MiniAppViewportState {
60
60
  height: number;
61
61
  stableHeight: number;
62
62
  }
63
+ interface MiniAppCustomLaunchParams {
64
+ customLaunchParams: Record<string, unknown>;
65
+ }
63
66
  interface MiniAppInitOptions {
64
67
  /**
65
68
  * Enables verbose logs for platforms that support it.
@@ -198,6 +201,10 @@ interface MiniAppAdapter {
198
201
  * Reads platform launch parameters, if available.
199
202
  */
200
203
  getLaunchParams?(): unknown;
204
+ /**
205
+ * Returns custom launch parameters that are not part of platform service fields.
206
+ */
207
+ getCustomLaunchParams(): MiniAppCustomLaunchParams;
201
208
  /**
202
209
  * Decodes platform specific start parameter.
203
210
  */
@@ -345,6 +352,7 @@ declare abstract class BaseMiniAppAdapter implements MiniAppAdapter {
345
352
  onAppearanceChange(callback: (appearance: 'dark' | 'light' | undefined) => void): () => void;
346
353
  getInitData(): string | undefined;
347
354
  getLaunchParams(): unknown;
355
+ getCustomLaunchParams(): MiniAppCustomLaunchParams;
348
356
  decodeStartParam(_param: string): unknown;
349
357
  requestFullscreen(): void;
350
358
  onViewportChange(callback: (state: {
@@ -444,6 +452,7 @@ declare class TelegramMiniAppAdapter extends BaseMiniAppAdapter {
444
452
  closeApp(): Promise<void>;
445
453
  getInitData(): string | undefined;
446
454
  getLaunchParams(): unknown;
455
+ getCustomLaunchParams(): MiniAppCustomLaunchParams;
447
456
  decodeStartParam(param: string): unknown;
448
457
  requestFullscreen(): void;
449
458
  getViewportInsets(): MiniAppViewportInsets | undefined;
@@ -472,6 +481,9 @@ declare class TelegramMiniAppAdapter extends BaseMiniAppAdapter {
472
481
  private safeHeightFromSdk;
473
482
  private stableHeightFromSdk;
474
483
  private notifyViewHide;
484
+ private normalizeDecodedStartParam;
485
+ private readCustomUrlParams;
486
+ private parseQueryString;
475
487
  private notifyViewRestore;
476
488
  protected onDestroy(): void;
477
489
  }
@@ -498,7 +510,9 @@ declare class VKMiniAppAdapter extends BaseMiniAppAdapter {
498
510
  }): Promise<void>;
499
511
  getEnvironment(): MiniAppEnvironmentInfo;
500
512
  getLaunchParams(): unknown;
513
+ getCustomLaunchParams(): MiniAppCustomLaunchParams;
501
514
  openExternalLink(url: string): Promise<void>;
515
+ private readCustomUrlParams;
502
516
  supports(capability: MiniAppCapability): Promise<boolean>;
503
517
  requestPhone(): Promise<string | null>;
504
518
  requestNotificationsPermission(): Promise<boolean>;
@@ -589,4 +603,4 @@ declare function trackPixelEvent(event: string, payload?: Record<string, unknown
589
603
 
590
604
  declare function getPlatform(): MiniAppPlatform;
591
605
 
592
- export { AdapterProvider, BaseMiniAppAdapter, type CreateAdapterOptions, MaxMiniAppAdapter, type MiniAppAdapter, type MiniAppCapability, type MiniAppEnvironmentInfo, type MiniAppInitOptions, type MiniAppPlatform, type MiniAppPopupOptions, type MiniAppQrScanOptions, type MiniAppShareStoryOptions, type MiniAppViewportState, ShellMiniAppAdapter, TelegramMiniAppAdapter, VKMiniAppAdapter, WebMiniAppAdapter, configureVkPixel, createAdapter, createShellAPI, detectPlatform, getActiveAdapter, getPlatform, isShell, isShellAndroid, isShellIOS, readShellPlatform, requestShellPushPermission, shell, storeShellToken, trackConversionEvent, trackPixelEvent, useAdapterTheme, useMiniAppAdapter, useSafeArea };
606
+ export { AdapterProvider, BaseMiniAppAdapter, type CreateAdapterOptions, MaxMiniAppAdapter, type MiniAppAdapter, type MiniAppCapability, type MiniAppCustomLaunchParams, type MiniAppEnvironmentInfo, type MiniAppInitOptions, type MiniAppPlatform, type MiniAppPopupOptions, type MiniAppQrScanOptions, type MiniAppShareStoryOptions, type MiniAppViewportState, ShellMiniAppAdapter, TelegramMiniAppAdapter, VKMiniAppAdapter, WebMiniAppAdapter, configureVkPixel, createAdapter, createShellAPI, detectPlatform, getActiveAdapter, getPlatform, isShell, isShellAndroid, isShellIOS, readShellPlatform, requestShellPushPermission, shell, storeShellToken, trackConversionEvent, trackPixelEvent, useAdapterTheme, useMiniAppAdapter, useSafeArea };
package/dist/index.js CHANGED
@@ -608,6 +608,9 @@ var BaseMiniAppAdapter = class {
608
608
  getLaunchParams() {
609
609
  return void 0;
610
610
  }
611
+ getCustomLaunchParams() {
612
+ return { customLaunchParams: {} };
613
+ }
611
614
  decodeStartParam(_param) {
612
615
  return void 0;
613
616
  }
@@ -1422,6 +1425,24 @@ var TelegramMiniAppAdapter = class extends BaseMiniAppAdapter {
1422
1425
  return void 0;
1423
1426
  }
1424
1427
  }
1428
+ getCustomLaunchParams() {
1429
+ const customFromUrl = this.readCustomUrlParams((key) => key.toLowerCase().startsWith("tgwebapp"));
1430
+ let customFromStartParam = {};
1431
+ try {
1432
+ const launchParams = retrieveLaunchParams();
1433
+ const startParam = launchParams.tgWebAppStartParam;
1434
+ if (typeof startParam === "string" && startParam) {
1435
+ customFromStartParam = this.normalizeDecodedStartParam(startParam);
1436
+ }
1437
+ } catch {
1438
+ }
1439
+ return {
1440
+ customLaunchParams: {
1441
+ ...customFromUrl,
1442
+ ...customFromStartParam
1443
+ }
1444
+ };
1445
+ }
1425
1446
  decodeStartParam(param) {
1426
1447
  try {
1427
1448
  return decodeStartParam(param);
@@ -1768,6 +1789,70 @@ var TelegramMiniAppAdapter = class extends BaseMiniAppAdapter {
1768
1789
  }
1769
1790
  }
1770
1791
  }
1792
+ normalizeDecodedStartParam(startParam) {
1793
+ let decoded;
1794
+ try {
1795
+ decoded = decodeStartParam(startParam);
1796
+ } catch {
1797
+ decoded = startParam;
1798
+ }
1799
+ if (decoded && typeof decoded === "object" && !Array.isArray(decoded)) {
1800
+ return { ...decoded };
1801
+ }
1802
+ if (typeof decoded === "string" && decoded) {
1803
+ const parsed = this.parseQueryString(decoded);
1804
+ if (Object.keys(parsed).length) {
1805
+ return parsed;
1806
+ }
1807
+ return { startParam: decoded };
1808
+ }
1809
+ return {};
1810
+ }
1811
+ readCustomUrlParams(isServiceParam) {
1812
+ if (typeof window === "undefined") {
1813
+ return {};
1814
+ }
1815
+ const result = {};
1816
+ const append = (source) => {
1817
+ const keys = /* @__PURE__ */ new Set();
1818
+ for (const [key] of source.entries()) {
1819
+ keys.add(key);
1820
+ }
1821
+ for (const key of keys) {
1822
+ if (isServiceParam(key)) {
1823
+ continue;
1824
+ }
1825
+ const values = source.getAll(key);
1826
+ if (!values.length) {
1827
+ continue;
1828
+ }
1829
+ result[key] = values.length === 1 ? values[0] : values;
1830
+ }
1831
+ };
1832
+ append(new URLSearchParams(window.location.search));
1833
+ const hash = window.location.hash.startsWith("#") ? window.location.hash.slice(1) : window.location.hash;
1834
+ if (hash && hash.includes("=")) {
1835
+ append(new URLSearchParams(hash));
1836
+ }
1837
+ return result;
1838
+ }
1839
+ parseQueryString(value) {
1840
+ const normalized = value.startsWith("?") ? value.slice(1) : value;
1841
+ const params = new URLSearchParams(normalized);
1842
+ const result = {};
1843
+ const keys = /* @__PURE__ */ new Set();
1844
+ for (const [key] of params.entries()) {
1845
+ keys.add(key);
1846
+ }
1847
+ for (const key of keys) {
1848
+ const values = params.getAll(key);
1849
+ if (!values.length) {
1850
+ continue;
1851
+ }
1852
+ result[key] = values.length === 1 ? values[0] : values;
1853
+ }
1854
+ return result;
1855
+ }
1771
1856
  notifyViewRestore() {
1772
1857
  for (const listener of this.viewRestoreListeners) {
1773
1858
  try {
@@ -1940,6 +2025,11 @@ var VKMiniAppAdapter = class extends BaseMiniAppAdapter {
1940
2025
  queryParams: this.queryParams
1941
2026
  };
1942
2027
  }
2028
+ getCustomLaunchParams() {
2029
+ return {
2030
+ customLaunchParams: this.readCustomUrlParams()
2031
+ };
2032
+ }
1943
2033
  async openExternalLink(url) {
1944
2034
  const a = document.createElement("a");
1945
2035
  a.href = url;
@@ -1950,6 +2040,38 @@ var VKMiniAppAdapter = class extends BaseMiniAppAdapter {
1950
2040
  a.click();
1951
2041
  a.remove();
1952
2042
  }
2043
+ readCustomUrlParams() {
2044
+ if (typeof window === "undefined") {
2045
+ return {};
2046
+ }
2047
+ const result = {};
2048
+ const isServiceParam = (key) => {
2049
+ const normalized = key.toLowerCase();
2050
+ return normalized.startsWith("vk_") || normalized === "sign";
2051
+ };
2052
+ const append = (source) => {
2053
+ const keys = /* @__PURE__ */ new Set();
2054
+ for (const [key] of source.entries()) {
2055
+ keys.add(key);
2056
+ }
2057
+ for (const key of keys) {
2058
+ if (isServiceParam(key)) {
2059
+ continue;
2060
+ }
2061
+ const values = source.getAll(key);
2062
+ if (!values.length) {
2063
+ continue;
2064
+ }
2065
+ result[key] = values.length === 1 ? values[0] : values;
2066
+ }
2067
+ };
2068
+ append(new URLSearchParams(window.location.search));
2069
+ const hash = window.location.hash.startsWith("#") ? window.location.hash.slice(1) : window.location.hash;
2070
+ if (hash && hash.includes("=")) {
2071
+ append(new URLSearchParams(hash));
2072
+ }
2073
+ return result;
2074
+ }
1953
2075
  async supports(capability) {
1954
2076
  switch (capability) {
1955
2077
  case "haptics": {