@tma.js/sdk 0.11.6 → 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.
Files changed (42) hide show
  1. package/dist/dts/components/CloudStorage/CloudStorage.d.ts +2 -2
  2. package/dist/dts/components/ThemeParams/ThemeParams.d.ts +4 -3
  3. package/dist/dts/components/ThemeParams/types.d.ts +2 -2
  4. package/dist/dts/components/WebApp/WebApp.d.ts +5 -4
  5. package/dist/dts/index.d.ts +2 -3
  6. package/dist/dts/init/creators/createBackButton.d.ts +2 -1
  7. package/dist/dts/init/creators/createClosingBehavior.d.ts +2 -1
  8. package/dist/dts/init/creators/createMainButton.d.ts +2 -1
  9. package/dist/dts/init/creators/createThemeParams.d.ts +7 -0
  10. package/dist/dts/init/creators/createViewport.d.ts +3 -2
  11. package/dist/dts/init/creators/createWebApp.d.ts +4 -2
  12. package/dist/dts/init/creators/index.d.ts +1 -1
  13. package/dist/dts/init/types.d.ts +5 -5
  14. package/dist/dts/launch-params.d.ts +3 -17
  15. package/dist/dts/state/State.d.ts +1 -1
  16. package/dist/dts/storage.d.ts +0 -1
  17. package/dist/dts/types.d.ts +0 -4
  18. package/dist/index.js +290 -304
  19. package/dist/index.js.map +1 -1
  20. package/dist/index.umd.cjs +1 -1
  21. package/dist/index.umd.cjs.map +1 -1
  22. package/package.json +7 -4
  23. package/src/components/MainButton/MainButton.ts +1 -1
  24. package/src/components/ThemeParams/ThemeParams.ts +3 -3
  25. package/src/components/ThemeParams/types.ts +5 -5
  26. package/src/components/WebApp/WebApp.ts +2 -1
  27. package/src/index.ts +2 -3
  28. package/src/init/creators/createBackButton.ts +7 -2
  29. package/src/init/creators/createClosingBehavior.ts +6 -2
  30. package/src/init/creators/createMainButton.ts +3 -1
  31. package/src/init/creators/{createSyncedThemeParams.ts → createThemeParams.ts} +3 -3
  32. package/src/init/creators/createViewport.ts +8 -4
  33. package/src/init/creators/createWebApp.ts +5 -2
  34. package/src/init/creators/index.ts +1 -1
  35. package/src/init/init.ts +67 -20
  36. package/src/init/types.ts +5 -5
  37. package/src/launch-params.ts +14 -55
  38. package/src/storage.ts +1 -2
  39. package/src/types.ts +0 -15
  40. package/dist/dts/init/creators/createSyncedThemeParams.d.ts +0 -7
  41. package/dist/dts/theme-params.d.ts +0 -18
  42. package/src/theme-params.ts +0 -34
@@ -1,4 +1,4 @@
1
- import { type RequestOptions } from '@tma.js/bridge';
1
+ import { postEvent as defaultPostEvent, type RequestOptions } from '@tma.js/bridge';
2
2
  import type { Version } from '@tma.js/utils';
3
3
  import { type SupportsFunc } from '../../supports.js';
4
4
  import type { CreateRequestIdFunc } from '../../types.js';
@@ -6,7 +6,7 @@ type WiredRequestOptions = Omit<RequestOptions, 'postEvent'>;
6
6
  export declare class CloudStorage {
7
7
  private readonly createRequestId;
8
8
  private readonly postEvent;
9
- constructor(version: Version, createRequestId: CreateRequestIdFunc, postEvent?: any);
9
+ constructor(version: Version, createRequestId: CreateRequestIdFunc, postEvent?: typeof defaultPostEvent);
10
10
  /**
11
11
  * Invokes custom method related to CloudStorage.
12
12
  * @param method - method name.
@@ -1,6 +1,7 @@
1
+ import { type ThemeParams as ThemeParamsType } from '@tma.js/theme-params';
1
2
  import { type RequestOptions } from '@tma.js/bridge';
2
3
  import type { RGB } from '@tma.js/colors';
3
- import { type ThemeParamsType } from '../../theme-params.js';
4
+ import type { ThemeParamsEvents } from './types.js';
4
5
  /**
5
6
  * Contains information about currently used theme by application.
6
7
  * @see https://core.telegram.org/bots/webapps#themeparams
@@ -56,11 +57,11 @@ export declare class ThemeParams {
56
57
  /**
57
58
  * Adds new event listener.
58
59
  */
59
- on: any;
60
+ on: <E extends "changed" | "backgroundColorChanged" | "textColorChanged" | "buttonColorChanged" | "buttonTextColorChanged" | "hintColorChanged" | "linkColorChanged" | "secondaryBackgroundColorChanged">(event: E, listener: import("@tma.js/event-emitter").EventListener<ThemeParamsEvents[E]>) => void;
60
61
  /**
61
62
  * Removes event listener.
62
63
  */
63
- off: any;
64
+ off: <E extends "changed" | "backgroundColorChanged" | "textColorChanged" | "buttonColorChanged" | "buttonTextColorChanged" | "hintColorChanged" | "linkColorChanged" | "secondaryBackgroundColorChanged">(event: E, listener: import("@tma.js/event-emitter").EventListener<ThemeParamsEvents[E]>) => void;
64
65
  /**
65
66
  * Returns secondary background color.
66
67
  */
@@ -1,8 +1,8 @@
1
1
  import type { HasUndefined, If } from '@tma.js/util-types';
2
- import type { ThemeParamsType } from '../../theme-params.js';
2
+ import type { ThemeParams } from '@tma.js/theme-params';
3
3
  import type { StateEvents } from '../../state/index.js';
4
4
  export type ThemeParamsState = {
5
- [K in keyof ThemeParamsType]-?: If<HasUndefined<ThemeParamsType[K]>, Exclude<ThemeParamsType[K], undefined> | null, ThemeParamsType[K]>;
5
+ [K in keyof ThemeParams]-?: If<HasUndefined<ThemeParams[K]>, Exclude<ThemeParams[K], undefined> | null, ThemeParams[K]>;
6
6
  };
7
7
  export type ThemeParamsEvents = StateEvents<ThemeParamsState>;
8
8
  export type ThemeParamsEventName = keyof ThemeParamsEvents;
@@ -1,9 +1,10 @@
1
1
  import { type Version } from '@tma.js/utils';
2
2
  import { type RGB } from '@tma.js/colors';
3
3
  import { type PhoneRequestedStatus, type WriteAccessRequestedStatus, type InvoiceStatus, type PostEvent } from '@tma.js/bridge';
4
+ import type { Platform } from '@tma.js/launch-params';
4
5
  import { type SupportsFunc } from '../../supports.js';
5
- import type { ColorScheme, Platform } from '../../types.js';
6
- import type { WebAppHeaderColor } from './types.js';
6
+ import type { ColorScheme } from '../../types.js';
7
+ import type { WebAppEvents, WebAppHeaderColor } from './types.js';
7
8
  /**
8
9
  * Provides common Web Apps functionality not covered by other system
9
10
  * components.
@@ -65,11 +66,11 @@ export declare class WebApp {
65
66
  /**
66
67
  * Adds new event listener.
67
68
  */
68
- on: any;
69
+ on: <E extends "changed" | "backgroundColorChanged" | "headerColorChanged">(event: E, listener: import("@tma.js/event-emitter").EventListener<WebAppEvents[E]>) => void;
69
70
  /**
70
71
  * Removes event listener.
71
72
  */
72
- off: any;
73
+ off: <E extends "changed" | "backgroundColorChanged" | "headerColorChanged">(event: E, listener: import("@tma.js/event-emitter").EventListener<WebAppEvents[E]>) => void;
73
74
  /**
74
75
  * Returns current Web App platform.
75
76
  */
@@ -1,8 +1,7 @@
1
1
  export * from './components/index.js';
2
- export { init, type InitResult, type InitOptions } from './init/index.js';
3
- export { MethodNotSupportedError } from './errors/index.js';
2
+ export * from './errors/index.js';
3
+ export * from './init/index.js';
4
4
  export * from './env.js';
5
5
  export * from './launch-params.js';
6
- export * from './theme-params.js';
7
6
  export * from './types.js';
8
7
  export * from './url.js';
@@ -3,7 +3,8 @@ import { BackButton } from '../../components/index.js';
3
3
  /**
4
4
  * Creates BackButton instance using last locally saved data also saving each state in
5
5
  * the storage.
6
+ * @param isPageReload - was current page reloaded.
6
7
  * @param version - platform version.
7
8
  * @param postEvent - Bridge postEvent function
8
9
  */
9
- export declare function createBackButton(version: string, postEvent: PostEvent): BackButton;
10
+ export declare function createBackButton(isPageReload: boolean, version: string, postEvent: PostEvent): BackButton;
@@ -3,6 +3,7 @@ import { ClosingBehaviour } from '../../components/index.js';
3
3
  /**
4
4
  * Creates ClosingBehaviour instance using last locally saved data also saving each state in
5
5
  * the storage.
6
+ * @param isPageReload - was current page reloaded.
6
7
  * @param postEvent - Bridge postEvent function
7
8
  */
8
- export declare function createClosingBehavior(postEvent: PostEvent): ClosingBehaviour;
9
+ export declare function createClosingBehavior(isPageReload: boolean, postEvent: PostEvent): ClosingBehaviour;
@@ -4,8 +4,9 @@ import { MainButton } from '../../components/index.js';
4
4
  /**
5
5
  * Creates MainButton instance using last locally saved data also saving each state in
6
6
  * the storage.
7
+ * @param isPageReload - was current page reloaded.
7
8
  * @param backgroundColor - background color.
8
9
  * @param textColor - text color.
9
10
  * @param postEvent - Bridge postEvent function
10
11
  */
11
- export declare function createMainButton(backgroundColor: RGB, textColor: RGB, postEvent: PostEvent): MainButton;
12
+ export declare function createMainButton(isPageReload: boolean, backgroundColor: RGB, textColor: RGB, postEvent: PostEvent): MainButton;
@@ -0,0 +1,7 @@
1
+ import type { ThemeParams as ThemeParamsType } from '@tma.js/theme-params';
2
+ import { ThemeParams } from '../../components/index.js';
3
+ /**
4
+ * Creates synced instance of ThemeParams.
5
+ * @param params - theme parameters.
6
+ */
7
+ export declare function createThemeParams(params: ThemeParamsType): ThemeParams;
@@ -1,10 +1,11 @@
1
1
  import type { PostEvent } from '@tma.js/bridge';
2
+ import type { Platform } from '@tma.js/launch-params';
2
3
  import { Viewport } from '../../components/index.js';
3
- import type { Platform } from '../../types.js';
4
4
  /**
5
5
  * Creates Viewport instance using last locally saved data also saving each state in
6
6
  * the storage.
7
+ * @param isPageReload - was current page reloaded.
7
8
  * @param platform - Telegram Web Apps platform name.
8
9
  * @param postEvent - Bridge postEvent function
9
10
  */
10
- export declare function createViewport(platform: Platform, postEvent: PostEvent): Promise<Viewport>;
11
+ export declare function createViewport(isPageReload: boolean, platform: Platform, postEvent: PostEvent): Promise<Viewport>;
@@ -1,14 +1,16 @@
1
1
  import type { RGB } from '@tma.js/colors';
2
2
  import type { PostEvent } from '@tma.js/bridge';
3
+ import type { Platform } from '@tma.js/launch-params';
3
4
  import { WebApp } from '../../components/index.js';
4
- import type { CreateRequestIdFunc, Platform } from '../../types.js';
5
+ import type { CreateRequestIdFunc } from '../../types.js';
5
6
  /**
6
7
  * Creates WebApp instance using last locally saved data also saving each state in
7
8
  * the storage.
9
+ * @param isPageReload - was current page reloaded.
8
10
  * @param backgroundColor - web app background color.
9
11
  * @param version - platform version.
10
12
  * @param platform - Telegram Web Apps platform name.
11
13
  * @param createRequestId - function which generates request identifiers.
12
14
  * @param postEvent - Bridge postEvent function
13
15
  */
14
- export declare function createWebApp(backgroundColor: RGB, version: string, platform: Platform, createRequestId: CreateRequestIdFunc, postEvent: PostEvent): WebApp;
16
+ export declare function createWebApp(isPageReload: boolean, backgroundColor: RGB, version: string, platform: Platform, createRequestId: CreateRequestIdFunc, postEvent: PostEvent): WebApp;
@@ -3,6 +3,6 @@ export * from './createClosingBehavior.js';
3
3
  export * from './createMainButton.js';
4
4
  export * from './createPostEvent.js';
5
5
  export * from './createRequestIdGenerator.js';
6
- export * from './createSyncedThemeParams.js';
6
+ export * from './createThemeParams.js';
7
7
  export * from './createViewport.js';
8
8
  export * from './createWebApp.js';
@@ -1,7 +1,7 @@
1
1
  import type { PostEvent } from '@tma.js/bridge';
2
+ import type { LaunchParams } from '@tma.js/launch-params';
2
3
  import type { BackButton, ClosingBehaviour, CloudStorage, HapticFeedback, InitData, MainButton, Popup, QRScanner, ThemeParams, Viewport, WebApp } from '../components/index.js';
3
- import type { LaunchParams } from '../launch-params.js';
4
- export type InitResult = {
4
+ export interface InitResult {
5
5
  backButton: BackButton;
6
6
  closingBehavior: ClosingBehaviour;
7
7
  cloudStorage: CloudStorage;
@@ -15,8 +15,8 @@ export type InitResult = {
15
15
  themeParams: ThemeParams;
16
16
  viewport: Viewport;
17
17
  webApp: WebApp;
18
- };
19
- export type InitCSSVarsSpecificOption = {
18
+ }
19
+ export interface InitCSSVarsSpecificOption {
20
20
  /**
21
21
  * Enables theme parameters CSS variables:
22
22
  * - `--tg-theme-bg-color`
@@ -46,7 +46,7 @@ export type InitCSSVarsSpecificOption = {
46
46
  * @see bindWebAppVariables
47
47
  */
48
48
  webApp?: true;
49
- };
49
+ }
50
50
  export type InitCSSVarsOption = boolean | InitCSSVarsSpecificOption;
51
51
  export interface InitOptions {
52
52
  /**
@@ -1,20 +1,6 @@
1
- import { type InitData } from '@tma.js/init-data';
2
- import { type ThemeParamsType } from './theme-params.js';
3
- import type { Platform } from './types.js';
4
- export interface LaunchParams {
5
- version: string;
6
- initData?: InitData;
7
- initDataRaw?: string;
8
- platform: Platform;
9
- themeParams: ThemeParamsType;
10
- }
1
+ import type { LaunchParams } from '@tma.js/launch-params';
11
2
  /**
12
- * Parses query parameters as launch parameters.
13
- * @param query - query parameters presented as string or URLSearchParams
14
- * instance.
15
- */
16
- export declare function parseLaunchParams(query: string | URLSearchParams): LaunchParams;
17
- /**
18
- * Extracts launch params from the current environment.
3
+ * Attempts to extract launch params from window.location.hash. In case, window.location.hash
4
+ * lacks of valid data, function attempts to extract launch params from the sessionStorage.
19
5
  */
20
6
  export declare function retrieveLaunchParams(): LaunchParams;
@@ -6,7 +6,7 @@ import type { StateEvents, StringKeys } from './types.js';
6
6
  export declare class State<S extends object> {
7
7
  private readonly state;
8
8
  private readonly ee?;
9
- constructor(state: S, ee?: EventEmitter<StateEvents<S>>);
9
+ constructor(state: S, ee?: EventEmitter<StateEvents<S>> | undefined);
10
10
  private emit;
11
11
  private internalSet;
12
12
  set<K extends StringKeys<S>>(key: K, value: S[K]): void;
@@ -28,7 +28,6 @@ interface StorageParams {
28
28
  backgroundColor: RGB;
29
29
  headerColor: HeaderColorKey | RGB;
30
30
  };
31
- 'launch-params': string;
32
31
  }
33
32
  /**
34
33
  * Key which could be used to store data in storage.
@@ -4,10 +4,6 @@ export type PostEvent = BridgePostEvent;
4
4
  * Color scheme.
5
5
  */
6
6
  export type ColorScheme = 'dark' | 'light';
7
- /**
8
- * Native Telegram application identifier.
9
- */
10
- export type Platform = 'android' | 'android_x' | 'ios' | 'macos' | 'tdesktop' | 'web' | 'weba' | 'unigram' | 'unknown' | string;
11
7
  /**
12
8
  * Function which generates unique request identifiers.
13
9
  */