@tma.js/bridge 1.4.0 → 1.4.1

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 (36) hide show
  1. package/dist/dts/events/events.d.ts +1 -1
  2. package/dist/dts/events/index.d.ts +2 -2
  3. package/dist/dts/events/parsers/clipboardTextReceived.d.ts +13 -0
  4. package/dist/dts/events/parsers/customMethodInvoked.d.ts +16 -0
  5. package/dist/dts/events/parsers/index.d.ts +9 -0
  6. package/dist/dts/events/parsers/invoiceClosed.d.ts +12 -0
  7. package/dist/dts/events/parsers/phoneRequested.d.ts +8 -0
  8. package/dist/dts/events/parsers/popupClosed.d.ts +8 -0
  9. package/dist/dts/events/parsers/qrTextReceived.d.ts +7 -0
  10. package/dist/dts/events/parsers/theme-changed.d.ts +42 -0
  11. package/dist/dts/events/parsers/viewportChanged.d.ts +19 -0
  12. package/dist/dts/events/parsers/writeAccessRequested.d.ts +8 -0
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.iife.js +1 -1
  16. package/dist/index.iife.js.map +1 -1
  17. package/dist/index.mjs +179 -159
  18. package/dist/index.mjs.map +1 -1
  19. package/package.json +2 -2
  20. package/src/events/emitter.ts +19 -19
  21. package/src/events/events.ts +1 -1
  22. package/src/events/index.ts +2 -2
  23. package/src/events/parsers/clipboardTextReceived.ts +27 -0
  24. package/src/events/parsers/customMethodInvoked.ts +26 -0
  25. package/src/events/parsers/index.ts +9 -0
  26. package/src/events/parsers/invoiceClosed.ts +26 -0
  27. package/src/events/parsers/phoneRequested.ts +14 -0
  28. package/src/events/parsers/popupClosed.ts +19 -0
  29. package/src/events/parsers/qrTextReceived.ts +14 -0
  30. package/src/events/parsers/theme-changed.ts +58 -0
  31. package/src/events/parsers/viewportChanged.ts +33 -0
  32. package/src/events/parsers/writeAccessRequested.ts +14 -0
  33. package/dist/dts/events/parsing.d.ts +0 -38
  34. package/dist/dts/events/payloads.d.ts +0 -93
  35. package/src/events/parsing.ts +0 -110
  36. package/src/events/payloads.ts +0 -125
@@ -1,93 +0,0 @@
1
- import type { RGB } from '@tma.js/colors';
2
- import type { RequestId } from '../shared.js';
3
- export interface ClipboardTextReceivedPayload {
4
- /**
5
- * Passed during the `web_app_read_text_from_clipboard` method invocation `req_id` value.
6
- */
7
- req_id: RequestId;
8
- /**
9
- * Data extracted from the clipboard. The returned value will have the type `string` only in
10
- * the case, application has access to the clipboard.
11
- */
12
- data?: string | null;
13
- }
14
- export interface CustomMethodInvokedPayload<R = unknown> {
15
- /**
16
- * Unique identifier of this invocation.
17
- */
18
- req_id: RequestId;
19
- /**
20
- * Method invocation successful result.
21
- */
22
- result?: R;
23
- /**
24
- * Method invocation error code.
25
- */
26
- error?: string;
27
- }
28
- export type InvoiceStatus = 'paid' | 'failed' | 'pending' | 'cancelled' | string;
29
- export interface InvoiceClosedPayload {
30
- /**
31
- * Passed during the `web_app_open_invoice` method invocation `slug` value.
32
- */
33
- slug: string;
34
- /**
35
- * Invoice status
36
- */
37
- status: InvoiceStatus;
38
- }
39
- export interface QrTextReceivedPayload {
40
- /**
41
- * Data extracted from the QR.
42
- */
43
- data?: string;
44
- }
45
- export type ThemeParamsKey = 'accent_text_color' | 'bg_color' | 'button_color' | 'button_text_color' | 'destructive_text_color' | 'header_bg_color' | 'hint_color' | 'link_color' | 'secondary_bg_color' | 'section_header_text_color' | 'section_bg_color' | 'subtitle_text_color' | 'text_color';
46
- export interface ThemeChangedPayload {
47
- /**
48
- * Map where the key is a theme stylesheet key and value is the corresponding color in
49
- * `#RRGGBB` format.
50
- */
51
- theme_params: {
52
- [Key in ThemeParamsKey]?: RGB;
53
- };
54
- }
55
- export interface ViewportChangedPayload {
56
- /**
57
- * The viewport height.
58
- */
59
- height: number;
60
- /**
61
- * The viewport width.
62
- */
63
- width: number;
64
- /**
65
- * Is the viewport currently expanded.
66
- */
67
- is_expanded: boolean;
68
- /**
69
- * Is the viewport current state stable and not going to change in the next moment.
70
- */
71
- is_state_stable: boolean;
72
- }
73
- export interface PopupClosedPayload {
74
- /**
75
- * Identifier of the clicked button. In case, the popup was closed without clicking any button,
76
- * this property will be omitted.
77
- */
78
- button_id?: string;
79
- }
80
- export type PhoneRequestedStatus = 'sent' | string;
81
- export interface PhoneRequestedPayload {
82
- /**
83
- * Request status.
84
- */
85
- status: PhoneRequestedStatus;
86
- }
87
- export type WriteAccessRequestedStatus = 'allowed' | string;
88
- export interface WriteAccessRequestedPayload {
89
- /**
90
- * Request status.
91
- */
92
- status: WriteAccessRequestedStatus;
93
- }
@@ -1,110 +0,0 @@
1
- import {
2
- number,
3
- string,
4
- boolean,
5
- json,
6
- rgb,
7
- createValueParserGenerator,
8
- } from '@tma.js/parsing';
9
-
10
- import type {
11
- ClipboardTextReceivedPayload, CustomMethodInvokedPayload,
12
- InvoiceClosedPayload, PhoneRequestedPayload,
13
- PopupClosedPayload, QrTextReceivedPayload,
14
- ThemeChangedPayload,
15
- ViewportChangedPayload, WriteAccessRequestedPayload,
16
- } from './payloads.js';
17
-
18
- function isNullOrUndefined(value: unknown): boolean {
19
- return value === null || value === undefined;
20
- }
21
-
22
- const rgbOptional = rgb().optional();
23
- const num = number();
24
-
25
- const windowWidthParser = createValueParserGenerator(
26
- (value) => (value === null || value === undefined
27
- ? window.innerWidth
28
- : num.parse(value)),
29
- );
30
-
31
- /**
32
- * Parses incoming value as ThemeChangedPayload.
33
- */
34
- export const themeChangedPayload = json<ThemeChangedPayload>({
35
- theme_params: json({
36
- accent_text_color: rgbOptional,
37
- bg_color: rgbOptional,
38
- button_color: rgbOptional,
39
- button_text_color: rgbOptional,
40
- destructive_text_color: rgbOptional,
41
- header_bg_color: rgbOptional,
42
- hint_color: rgbOptional,
43
- link_color: rgbOptional,
44
- secondary_bg_color: rgbOptional,
45
- section_bg_color: rgbOptional,
46
- section_header_text_color: rgbOptional,
47
- subtitle_text_color: rgbOptional,
48
- text_color: rgbOptional,
49
- }),
50
- });
51
-
52
- /**
53
- * Parses incoming value as ViewportChangedPayload.
54
- * @param value - value to parse.
55
- */
56
- export const viewportChangedPayload = json<ViewportChangedPayload>({
57
- height: number(),
58
- width: windowWidthParser(),
59
- is_state_stable: boolean(),
60
- is_expanded: boolean(),
61
- });
62
-
63
- /**
64
- * Parses incoming value as PopupClosedPayload.
65
- */
66
- export const popupClosedPayload = json<PopupClosedPayload>({
67
- button_id: string({ isEmpty: isNullOrUndefined }).optional(),
68
- });
69
-
70
- /**
71
- * Parses incoming value as QrTextReceivedPayload.
72
- */
73
- export const qrTextReceivedPayload = json<QrTextReceivedPayload>({
74
- data: string().optional(),
75
- });
76
-
77
- /**
78
- * Parses incoming value as InvoiceClosedPayload.
79
- */
80
- export const invoiceClosedPayload = json<InvoiceClosedPayload>({
81
- slug: string(),
82
- status: string(),
83
- });
84
-
85
- /**
86
- * Parses incoming value as clipboard text received payload.
87
- */
88
- export const clipboardTextReceivedPayload = json<ClipboardTextReceivedPayload>({
89
- req_id: string(),
90
- data: (value) => (value === null ? value : string().optional().parse(value)),
91
- });
92
-
93
- /**
94
- * Parses incoming value as WriteAccessRequestedPayload.
95
- */
96
- export const writeAccessRequestedPayload = json<WriteAccessRequestedPayload>({ status: string() });
97
-
98
- /**
99
- * Parses incoming value as PhoneRequestedPayload.
100
- */
101
- export const phoneRequestedPayload = json<PhoneRequestedPayload>({ status: string() });
102
-
103
- /**
104
- * Parses incoming value as CustomMethodInvokedPayload.
105
- */
106
- export const customMethodInvokedPayload = json<CustomMethodInvokedPayload>({
107
- req_id: string(),
108
- result: (value) => value,
109
- error: string().optional(),
110
- });
@@ -1,125 +0,0 @@
1
- import type { RGB } from '@tma.js/colors';
2
-
3
- import type { RequestId } from '../shared.js';
4
-
5
- export interface ClipboardTextReceivedPayload {
6
- /**
7
- * Passed during the `web_app_read_text_from_clipboard` method invocation `req_id` value.
8
- */
9
- req_id: RequestId;
10
- /**
11
- * Data extracted from the clipboard. The returned value will have the type `string` only in
12
- * the case, application has access to the clipboard.
13
- */
14
- data?: string | null;
15
- }
16
-
17
- export interface CustomMethodInvokedPayload<R = unknown> {
18
- /**
19
- * Unique identifier of this invocation.
20
- */
21
- req_id: RequestId;
22
- /**
23
- * Method invocation successful result.
24
- */
25
- result?: R;
26
- /**
27
- * Method invocation error code.
28
- */
29
- error?: string;
30
- }
31
-
32
- export type InvoiceStatus =
33
- | 'paid'
34
- | 'failed'
35
- | 'pending'
36
- | 'cancelled'
37
- | string;
38
-
39
- export interface InvoiceClosedPayload {
40
- /**
41
- * Passed during the `web_app_open_invoice` method invocation `slug` value.
42
- */
43
- slug: string;
44
- /**
45
- * Invoice status
46
- */
47
- status: InvoiceStatus;
48
- }
49
-
50
- export interface QrTextReceivedPayload {
51
- /**
52
- * Data extracted from the QR.
53
- */
54
- data?: string;
55
- }
56
-
57
- export type ThemeParamsKey =
58
- | 'accent_text_color'
59
- | 'bg_color'
60
- | 'button_color'
61
- | 'button_text_color'
62
- | 'destructive_text_color'
63
- | 'header_bg_color'
64
- | 'hint_color'
65
- | 'link_color'
66
- | 'secondary_bg_color'
67
- | 'section_header_text_color'
68
- | 'section_bg_color'
69
- | 'subtitle_text_color'
70
- | 'text_color';
71
-
72
- export interface ThemeChangedPayload {
73
- /**
74
- * Map where the key is a theme stylesheet key and value is the corresponding color in
75
- * `#RRGGBB` format.
76
- */
77
- theme_params: {
78
- [Key in ThemeParamsKey]?: RGB;
79
- };
80
- }
81
-
82
- export interface ViewportChangedPayload {
83
- /**
84
- * The viewport height.
85
- */
86
- height: number;
87
- /**
88
- * The viewport width.
89
- */
90
- width: number;
91
- /**
92
- * Is the viewport currently expanded.
93
- */
94
- is_expanded: boolean;
95
- /**
96
- * Is the viewport current state stable and not going to change in the next moment.
97
- */
98
- is_state_stable: boolean;
99
- }
100
-
101
- export interface PopupClosedPayload {
102
- /**
103
- * Identifier of the clicked button. In case, the popup was closed without clicking any button,
104
- * this property will be omitted.
105
- */
106
- button_id?: string;
107
- }
108
-
109
- export type PhoneRequestedStatus = 'sent' | string;
110
-
111
- export interface PhoneRequestedPayload {
112
- /**
113
- * Request status.
114
- */
115
- status: PhoneRequestedStatus;
116
- }
117
-
118
- export type WriteAccessRequestedStatus = 'allowed' | string;
119
-
120
- export interface WriteAccessRequestedPayload {
121
- /**
122
- * Request status.
123
- */
124
- status: WriteAccessRequestedStatus;
125
- }