@wowlabtech/mini-app-adapter 0.2.7 → 0.2.81
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 +105 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -6
- package/dist/index.d.ts +13 -6
- package/dist/index.js +105 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -60,6 +60,10 @@ interface MiniAppViewportState {
|
|
|
60
60
|
height: number;
|
|
61
61
|
stableHeight: number;
|
|
62
62
|
}
|
|
63
|
+
interface MiniAppLaunchParams {
|
|
64
|
+
launchParams?: unknown;
|
|
65
|
+
customLaunchParams: Record<string, unknown>;
|
|
66
|
+
}
|
|
63
67
|
interface MiniAppInitOptions {
|
|
64
68
|
/**
|
|
65
69
|
* Enables verbose logs for platforms that support it.
|
|
@@ -197,7 +201,7 @@ interface MiniAppAdapter {
|
|
|
197
201
|
/**
|
|
198
202
|
* Reads platform launch parameters, if available.
|
|
199
203
|
*/
|
|
200
|
-
getLaunchParams?():
|
|
204
|
+
getLaunchParams?(): MiniAppLaunchParams | undefined;
|
|
201
205
|
/**
|
|
202
206
|
* Decodes platform specific start parameter.
|
|
203
207
|
*/
|
|
@@ -344,7 +348,7 @@ declare abstract class BaseMiniAppAdapter implements MiniAppAdapter {
|
|
|
344
348
|
setBackButtonVisibility(_visible: boolean): void;
|
|
345
349
|
onAppearanceChange(callback: (appearance: 'dark' | 'light' | undefined) => void): () => void;
|
|
346
350
|
getInitData(): string | undefined;
|
|
347
|
-
getLaunchParams():
|
|
351
|
+
getLaunchParams(): MiniAppLaunchParams | undefined;
|
|
348
352
|
decodeStartParam(_param: string): unknown;
|
|
349
353
|
requestFullscreen(): void;
|
|
350
354
|
onViewportChange(callback: (state: {
|
|
@@ -378,6 +382,7 @@ declare abstract class BaseMiniAppAdapter implements MiniAppAdapter {
|
|
|
378
382
|
protected notifyEnvironmentChanged(): void;
|
|
379
383
|
protected onDestroy(): void;
|
|
380
384
|
protected registerDisposable(disposable: Disposable): () => void;
|
|
385
|
+
protected readCustomUrlParams(isServiceParam?: (key: string) => boolean): Record<string, unknown>;
|
|
381
386
|
private applyScrollGuards;
|
|
382
387
|
}
|
|
383
388
|
|
|
@@ -389,7 +394,7 @@ declare class MaxMiniAppAdapter extends BaseMiniAppAdapter {
|
|
|
389
394
|
init(_options?: MiniAppInitOptions): Promise<void>;
|
|
390
395
|
supports(capability: MiniAppCapability): boolean;
|
|
391
396
|
getInitData(): string | undefined;
|
|
392
|
-
getLaunchParams():
|
|
397
|
+
getLaunchParams(): MiniAppLaunchParams | undefined;
|
|
393
398
|
onBackButton(callback: () => void): () => void;
|
|
394
399
|
setBackButtonVisibility(visible: boolean): void;
|
|
395
400
|
openExternalLink(url: string): Promise<void>;
|
|
@@ -443,7 +448,7 @@ declare class TelegramMiniAppAdapter extends BaseMiniAppAdapter {
|
|
|
443
448
|
scanQRCode(options?: MiniAppQrScanOptions): Promise<string | null>;
|
|
444
449
|
closeApp(): Promise<void>;
|
|
445
450
|
getInitData(): string | undefined;
|
|
446
|
-
getLaunchParams():
|
|
451
|
+
getLaunchParams(): MiniAppLaunchParams | undefined;
|
|
447
452
|
decodeStartParam(param: string): unknown;
|
|
448
453
|
requestFullscreen(): void;
|
|
449
454
|
getViewportInsets(): MiniAppViewportInsets | undefined;
|
|
@@ -472,6 +477,8 @@ declare class TelegramMiniAppAdapter extends BaseMiniAppAdapter {
|
|
|
472
477
|
private safeHeightFromSdk;
|
|
473
478
|
private stableHeightFromSdk;
|
|
474
479
|
private notifyViewHide;
|
|
480
|
+
private normalizeDecodedStartParam;
|
|
481
|
+
private parseQueryString;
|
|
475
482
|
private notifyViewRestore;
|
|
476
483
|
protected onDestroy(): void;
|
|
477
484
|
}
|
|
@@ -497,7 +504,7 @@ declare class VKMiniAppAdapter extends BaseMiniAppAdapter {
|
|
|
497
504
|
background?: string;
|
|
498
505
|
}): Promise<void>;
|
|
499
506
|
getEnvironment(): MiniAppEnvironmentInfo;
|
|
500
|
-
getLaunchParams():
|
|
507
|
+
getLaunchParams(): MiniAppLaunchParams | undefined;
|
|
501
508
|
openExternalLink(url: string): Promise<void>;
|
|
502
509
|
supports(capability: MiniAppCapability): Promise<boolean>;
|
|
503
510
|
requestPhone(): Promise<string | null>;
|
|
@@ -589,4 +596,4 @@ declare function trackPixelEvent(event: string, payload?: Record<string, unknown
|
|
|
589
596
|
|
|
590
597
|
declare function getPlatform(): MiniAppPlatform;
|
|
591
598
|
|
|
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 };
|
|
599
|
+
export { AdapterProvider, BaseMiniAppAdapter, type CreateAdapterOptions, MaxMiniAppAdapter, type MiniAppAdapter, type MiniAppCapability, type MiniAppEnvironmentInfo, type MiniAppInitOptions, type MiniAppLaunchParams, 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,10 @@ interface MiniAppViewportState {
|
|
|
60
60
|
height: number;
|
|
61
61
|
stableHeight: number;
|
|
62
62
|
}
|
|
63
|
+
interface MiniAppLaunchParams {
|
|
64
|
+
launchParams?: unknown;
|
|
65
|
+
customLaunchParams: Record<string, unknown>;
|
|
66
|
+
}
|
|
63
67
|
interface MiniAppInitOptions {
|
|
64
68
|
/**
|
|
65
69
|
* Enables verbose logs for platforms that support it.
|
|
@@ -197,7 +201,7 @@ interface MiniAppAdapter {
|
|
|
197
201
|
/**
|
|
198
202
|
* Reads platform launch parameters, if available.
|
|
199
203
|
*/
|
|
200
|
-
getLaunchParams?():
|
|
204
|
+
getLaunchParams?(): MiniAppLaunchParams | undefined;
|
|
201
205
|
/**
|
|
202
206
|
* Decodes platform specific start parameter.
|
|
203
207
|
*/
|
|
@@ -344,7 +348,7 @@ declare abstract class BaseMiniAppAdapter implements MiniAppAdapter {
|
|
|
344
348
|
setBackButtonVisibility(_visible: boolean): void;
|
|
345
349
|
onAppearanceChange(callback: (appearance: 'dark' | 'light' | undefined) => void): () => void;
|
|
346
350
|
getInitData(): string | undefined;
|
|
347
|
-
getLaunchParams():
|
|
351
|
+
getLaunchParams(): MiniAppLaunchParams | undefined;
|
|
348
352
|
decodeStartParam(_param: string): unknown;
|
|
349
353
|
requestFullscreen(): void;
|
|
350
354
|
onViewportChange(callback: (state: {
|
|
@@ -378,6 +382,7 @@ declare abstract class BaseMiniAppAdapter implements MiniAppAdapter {
|
|
|
378
382
|
protected notifyEnvironmentChanged(): void;
|
|
379
383
|
protected onDestroy(): void;
|
|
380
384
|
protected registerDisposable(disposable: Disposable): () => void;
|
|
385
|
+
protected readCustomUrlParams(isServiceParam?: (key: string) => boolean): Record<string, unknown>;
|
|
381
386
|
private applyScrollGuards;
|
|
382
387
|
}
|
|
383
388
|
|
|
@@ -389,7 +394,7 @@ declare class MaxMiniAppAdapter extends BaseMiniAppAdapter {
|
|
|
389
394
|
init(_options?: MiniAppInitOptions): Promise<void>;
|
|
390
395
|
supports(capability: MiniAppCapability): boolean;
|
|
391
396
|
getInitData(): string | undefined;
|
|
392
|
-
getLaunchParams():
|
|
397
|
+
getLaunchParams(): MiniAppLaunchParams | undefined;
|
|
393
398
|
onBackButton(callback: () => void): () => void;
|
|
394
399
|
setBackButtonVisibility(visible: boolean): void;
|
|
395
400
|
openExternalLink(url: string): Promise<void>;
|
|
@@ -443,7 +448,7 @@ declare class TelegramMiniAppAdapter extends BaseMiniAppAdapter {
|
|
|
443
448
|
scanQRCode(options?: MiniAppQrScanOptions): Promise<string | null>;
|
|
444
449
|
closeApp(): Promise<void>;
|
|
445
450
|
getInitData(): string | undefined;
|
|
446
|
-
getLaunchParams():
|
|
451
|
+
getLaunchParams(): MiniAppLaunchParams | undefined;
|
|
447
452
|
decodeStartParam(param: string): unknown;
|
|
448
453
|
requestFullscreen(): void;
|
|
449
454
|
getViewportInsets(): MiniAppViewportInsets | undefined;
|
|
@@ -472,6 +477,8 @@ declare class TelegramMiniAppAdapter extends BaseMiniAppAdapter {
|
|
|
472
477
|
private safeHeightFromSdk;
|
|
473
478
|
private stableHeightFromSdk;
|
|
474
479
|
private notifyViewHide;
|
|
480
|
+
private normalizeDecodedStartParam;
|
|
481
|
+
private parseQueryString;
|
|
475
482
|
private notifyViewRestore;
|
|
476
483
|
protected onDestroy(): void;
|
|
477
484
|
}
|
|
@@ -497,7 +504,7 @@ declare class VKMiniAppAdapter extends BaseMiniAppAdapter {
|
|
|
497
504
|
background?: string;
|
|
498
505
|
}): Promise<void>;
|
|
499
506
|
getEnvironment(): MiniAppEnvironmentInfo;
|
|
500
|
-
getLaunchParams():
|
|
507
|
+
getLaunchParams(): MiniAppLaunchParams | undefined;
|
|
501
508
|
openExternalLink(url: string): Promise<void>;
|
|
502
509
|
supports(capability: MiniAppCapability): Promise<boolean>;
|
|
503
510
|
requestPhone(): Promise<string | null>;
|
|
@@ -589,4 +596,4 @@ declare function trackPixelEvent(event: string, payload?: Record<string, unknown
|
|
|
589
596
|
|
|
590
597
|
declare function getPlatform(): MiniAppPlatform;
|
|
591
598
|
|
|
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 };
|
|
599
|
+
export { AdapterProvider, BaseMiniAppAdapter, type CreateAdapterOptions, MaxMiniAppAdapter, type MiniAppAdapter, type MiniAppCapability, type MiniAppEnvironmentInfo, type MiniAppInitOptions, type MiniAppLaunchParams, 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
|
@@ -606,7 +606,9 @@ var BaseMiniAppAdapter = class {
|
|
|
606
606
|
return void 0;
|
|
607
607
|
}
|
|
608
608
|
getLaunchParams() {
|
|
609
|
-
return
|
|
609
|
+
return {
|
|
610
|
+
customLaunchParams: this.readCustomUrlParams()
|
|
611
|
+
};
|
|
610
612
|
}
|
|
611
613
|
decodeStartParam(_param) {
|
|
612
614
|
return void 0;
|
|
@@ -747,6 +749,34 @@ var BaseMiniAppAdapter = class {
|
|
|
747
749
|
registerDisposable(disposable) {
|
|
748
750
|
return this.disposables.add(disposable);
|
|
749
751
|
}
|
|
752
|
+
readCustomUrlParams(isServiceParam) {
|
|
753
|
+
if (typeof window === "undefined") {
|
|
754
|
+
return {};
|
|
755
|
+
}
|
|
756
|
+
const result = {};
|
|
757
|
+
const append = (source) => {
|
|
758
|
+
const keys = /* @__PURE__ */ new Set();
|
|
759
|
+
for (const [key] of source.entries()) {
|
|
760
|
+
keys.add(key);
|
|
761
|
+
}
|
|
762
|
+
for (const key of keys) {
|
|
763
|
+
if (isServiceParam?.(key)) {
|
|
764
|
+
continue;
|
|
765
|
+
}
|
|
766
|
+
const values = source.getAll(key);
|
|
767
|
+
if (!values.length) {
|
|
768
|
+
continue;
|
|
769
|
+
}
|
|
770
|
+
result[key] = values.length === 1 ? values[0] : values;
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
append(new URLSearchParams(window.location.search));
|
|
774
|
+
const hash = window.location.hash.startsWith("#") ? window.location.hash.slice(1) : window.location.hash;
|
|
775
|
+
if (hash && hash.includes("=")) {
|
|
776
|
+
append(new URLSearchParams(hash));
|
|
777
|
+
}
|
|
778
|
+
return result;
|
|
779
|
+
}
|
|
750
780
|
applyScrollGuards() {
|
|
751
781
|
if (typeof document === "undefined") {
|
|
752
782
|
return void 0;
|
|
@@ -831,7 +861,10 @@ var MaxMiniAppAdapter = class extends BaseMiniAppAdapter {
|
|
|
831
861
|
return this.initData;
|
|
832
862
|
}
|
|
833
863
|
getLaunchParams() {
|
|
834
|
-
return
|
|
864
|
+
return {
|
|
865
|
+
launchParams: this.initDataUnsafe,
|
|
866
|
+
customLaunchParams: this.readCustomUrlParams()
|
|
867
|
+
};
|
|
835
868
|
}
|
|
836
869
|
onBackButton(callback) {
|
|
837
870
|
const bridge2 = getMaxBridge();
|
|
@@ -1416,10 +1449,28 @@ var TelegramMiniAppAdapter = class extends BaseMiniAppAdapter {
|
|
|
1416
1449
|
}
|
|
1417
1450
|
}
|
|
1418
1451
|
getLaunchParams() {
|
|
1452
|
+
const customFromUrl = this.readCustomUrlParams((key) => key.toLowerCase().startsWith("tgwebapp"));
|
|
1453
|
+
let customFromStartParam = {};
|
|
1419
1454
|
try {
|
|
1420
|
-
|
|
1455
|
+
const launchParams = retrieveLaunchParams();
|
|
1456
|
+
const startParam = launchParams.tgWebAppStartParam;
|
|
1457
|
+
if (typeof startParam === "string" && startParam) {
|
|
1458
|
+
customFromStartParam = this.normalizeDecodedStartParam(startParam);
|
|
1459
|
+
}
|
|
1460
|
+
return {
|
|
1461
|
+
launchParams,
|
|
1462
|
+
customLaunchParams: {
|
|
1463
|
+
...customFromUrl,
|
|
1464
|
+
...customFromStartParam
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1421
1467
|
} catch {
|
|
1422
|
-
return
|
|
1468
|
+
return {
|
|
1469
|
+
customLaunchParams: {
|
|
1470
|
+
...customFromUrl,
|
|
1471
|
+
...customFromStartParam
|
|
1472
|
+
}
|
|
1473
|
+
};
|
|
1423
1474
|
}
|
|
1424
1475
|
}
|
|
1425
1476
|
decodeStartParam(param) {
|
|
@@ -1768,6 +1819,42 @@ var TelegramMiniAppAdapter = class extends BaseMiniAppAdapter {
|
|
|
1768
1819
|
}
|
|
1769
1820
|
}
|
|
1770
1821
|
}
|
|
1822
|
+
normalizeDecodedStartParam(startParam) {
|
|
1823
|
+
let decoded;
|
|
1824
|
+
try {
|
|
1825
|
+
decoded = decodeStartParam(startParam);
|
|
1826
|
+
} catch {
|
|
1827
|
+
decoded = startParam;
|
|
1828
|
+
}
|
|
1829
|
+
if (decoded && typeof decoded === "object" && !Array.isArray(decoded)) {
|
|
1830
|
+
return { ...decoded };
|
|
1831
|
+
}
|
|
1832
|
+
if (typeof decoded === "string" && decoded) {
|
|
1833
|
+
const parsed = this.parseQueryString(decoded);
|
|
1834
|
+
if (Object.keys(parsed).length) {
|
|
1835
|
+
return parsed;
|
|
1836
|
+
}
|
|
1837
|
+
return { startParam: decoded };
|
|
1838
|
+
}
|
|
1839
|
+
return {};
|
|
1840
|
+
}
|
|
1841
|
+
parseQueryString(value) {
|
|
1842
|
+
const normalized = value.startsWith("?") ? value.slice(1) : value;
|
|
1843
|
+
const params = new URLSearchParams(normalized);
|
|
1844
|
+
const result = {};
|
|
1845
|
+
const keys = /* @__PURE__ */ new Set();
|
|
1846
|
+
for (const [key] of params.entries()) {
|
|
1847
|
+
keys.add(key);
|
|
1848
|
+
}
|
|
1849
|
+
for (const key of keys) {
|
|
1850
|
+
const values = params.getAll(key);
|
|
1851
|
+
if (!values.length) {
|
|
1852
|
+
continue;
|
|
1853
|
+
}
|
|
1854
|
+
result[key] = values.length === 1 ? values[0] : values;
|
|
1855
|
+
}
|
|
1856
|
+
return result;
|
|
1857
|
+
}
|
|
1771
1858
|
notifyViewRestore() {
|
|
1772
1859
|
for (const listener of this.viewRestoreListeners) {
|
|
1773
1860
|
try {
|
|
@@ -1933,11 +2020,22 @@ var VKMiniAppAdapter = class extends BaseMiniAppAdapter {
|
|
|
1933
2020
|
}
|
|
1934
2021
|
getLaunchParams() {
|
|
1935
2022
|
if (!this.launchParams) {
|
|
1936
|
-
return
|
|
2023
|
+
return {
|
|
2024
|
+
customLaunchParams: this.readCustomUrlParams((key) => {
|
|
2025
|
+
const normalized = key.toLowerCase();
|
|
2026
|
+
return normalized.startsWith("vk_") || normalized === "sign";
|
|
2027
|
+
})
|
|
2028
|
+
};
|
|
1937
2029
|
}
|
|
1938
2030
|
return {
|
|
1939
|
-
launchParams:
|
|
1940
|
-
|
|
2031
|
+
launchParams: {
|
|
2032
|
+
bridge: this.launchParams,
|
|
2033
|
+
query: this.queryParams
|
|
2034
|
+
},
|
|
2035
|
+
customLaunchParams: this.readCustomUrlParams((key) => {
|
|
2036
|
+
const normalized = key.toLowerCase();
|
|
2037
|
+
return normalized.startsWith("vk_") || normalized === "sign";
|
|
2038
|
+
})
|
|
1941
2039
|
};
|
|
1942
2040
|
}
|
|
1943
2041
|
async openExternalLink(url) {
|