@matreshka/bff 0.17.0 → 0.19.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.
- package/dist/components/board.d.ts +0 -3
- package/dist/components/board.js +3 -11
- package/dist/components/camera.d.ts +0 -3
- package/dist/components/camera.js +4 -11
- package/dist/components/component.d.ts +17 -1
- package/dist/components/component.js +19 -2
- package/dist/components/container.js +8 -11
- package/dist/components/dialog.d.ts +0 -3
- package/dist/components/dialog.js +4 -11
- package/dist/components/file-upload-area.js +8 -11
- package/dist/components/form.js +8 -11
- package/dist/components/grid.js +7 -11
- package/dist/components/map.d.ts +0 -3
- package/dist/components/map.js +2 -12
- package/dist/components/page.d.ts +0 -1
- package/dist/components/page.js +4 -10
- package/dist/components/popover.d.ts +0 -3
- package/dist/components/popover.js +4 -11
- package/dist/components/stack.d.ts +1 -4
- package/dist/components/stack.js +4 -11
- package/dist/core/utils/serialize-component-tree.d.ts +3 -0
- package/dist/core/utils/serialize-component-tree.js +21 -0
- package/dist/platforms/browser-platform.d.ts +21 -37
- package/dist/platforms/browser-platform.js +61 -104
- package/dist/platforms/max-mini-app-platform.d.ts +2 -8
- package/dist/platforms/max-mini-app-platform.js +10 -21
- package/dist/platforms/mobile-platform.d.ts +32 -58
- package/dist/platforms/mobile-platform.js +139 -211
- package/dist/platforms/platform.d.ts +32 -49
- package/dist/platforms/platform.js +77 -87
- package/dist/platforms/telegram-mini-app-platform.d.ts +16 -34
- package/dist/platforms/telegram-mini-app-platform.js +41 -92
- package/dist/platforms/utils/client-back-platform-action.d.ts +9 -0
- package/dist/platforms/utils/client-back-platform-action.js +48 -0
- package/dist/platforms/utils/client-navigate-platform-action.d.ts +19 -0
- package/dist/platforms/utils/client-navigate-platform-action.js +60 -0
- package/dist/platforms/utils/client-reload-platform-action.d.ts +8 -0
- package/dist/platforms/utils/client-reload-platform-action.js +41 -0
- package/dist/platforms/utils/client-route-page-wait.d.ts +11 -0
- package/dist/platforms/utils/client-route-page-wait.js +33 -0
- package/dist/platforms/utils/match-navigate-path.d.ts +11 -0
- package/dist/platforms/utils/match-navigate-path.js +95 -0
- package/dist/platforms/utils/targeted-client-platform-action.d.ts +11 -0
- package/dist/platforms/utils/targeted-client-platform-action.js +80 -0
- package/dist/platforms/utils/targeted-client-platform-stream.d.ts +17 -0
- package/dist/platforms/utils/targeted-client-platform-stream.js +90 -0
- package/package.json +2 -2
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { PlatformEnumeratedDevice } from "@matreshka/shared/messages/client-to-bff/platforms/platform-enumerate-devices-success-message";
|
|
1
|
+
import type { PlatformEnumeratedDevice } from "@matreshka/shared/messages/client-to-bff/platforms/platform-enumerate-devices-success-message";
|
|
2
|
+
import type { Observable } from "rxjs";
|
|
2
3
|
import { Dialog, Popover } from "../components";
|
|
3
4
|
import { Overlay } from "../components/types/container-overlay";
|
|
4
5
|
import { Client, Componentable, ComponentInstance, ContextValueRef } from "../core";
|
|
5
6
|
import { type PopoverShowComponent, type PopoverShowPlacement } from "./popover-show";
|
|
7
|
+
import { type NavigateResult } from "./utils/client-navigate-platform-action";
|
|
8
|
+
export type { NavigateResult };
|
|
6
9
|
/**
|
|
7
10
|
* Абстрактный класс платформы, управляющий клиентом и его состоянием.
|
|
8
11
|
*/
|
|
@@ -18,76 +21,57 @@ export declare abstract class Platform {
|
|
|
18
21
|
*
|
|
19
22
|
* @param path Путь, по которому необходимо перейти.
|
|
20
23
|
*/
|
|
21
|
-
navigate(path: string):
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
*/
|
|
25
|
-
back(): void;
|
|
24
|
+
navigate(path: string): Observable<NavigateResult>;
|
|
25
|
+
/** Переходит на предыдущую страницу в истории навигации клиента. */
|
|
26
|
+
back(): Observable<void>;
|
|
26
27
|
/**
|
|
27
28
|
* Перезагружает клиентское приложение.
|
|
28
|
-
*/
|
|
29
|
-
reload(): void;
|
|
30
|
-
/**
|
|
31
|
-
* Включает режим конфиденциальности.
|
|
32
|
-
*/
|
|
33
|
-
enablePrivacyMode(): void;
|
|
34
|
-
/**
|
|
35
|
-
* Отключает режим конфиденциальности.
|
|
36
|
-
*/
|
|
37
|
-
disablePrivacyMode(): void;
|
|
38
|
-
/**
|
|
39
|
-
* Явно включает светлую цветовую схему на клиенте.
|
|
40
|
-
*/
|
|
41
|
-
setColorSchemeLight(): void;
|
|
42
|
-
/**
|
|
43
|
-
* Явно включает тёмную цветовую схему на клиенте.
|
|
44
|
-
*/
|
|
45
|
-
setColorSchemeDark(): void;
|
|
46
|
-
/**
|
|
47
|
-
* Сбрасывает выбор темы: снова используется системная схема.
|
|
48
|
-
*/
|
|
49
|
-
setColorSchemeSystem(): void;
|
|
50
|
-
/**
|
|
51
|
-
* Отображает диалоговое окно.
|
|
52
29
|
*
|
|
53
|
-
* @
|
|
30
|
+
* Завершение observable — {@link Client.reconnect$} (переподключение WS с тем же token),
|
|
31
|
+
* а не ack с клиента до reload.
|
|
54
32
|
*/
|
|
55
|
-
|
|
33
|
+
reload(): Observable<void>;
|
|
34
|
+
/** Включает режим конфиденциальности. */
|
|
35
|
+
enablePrivacyMode(): Observable<void>;
|
|
36
|
+
/** Отключает режим конфиденциальности. */
|
|
37
|
+
disablePrivacyMode(): Observable<void>;
|
|
38
|
+
/** Явно включает светлую цветовую схему на клиенте. */
|
|
39
|
+
setColorSchemeLight(): Observable<void>;
|
|
40
|
+
/** Явно включает тёмную цветовую схему на клиенте. */
|
|
41
|
+
setColorSchemeDark(): Observable<void>;
|
|
42
|
+
/** Сбрасывает выбор темы: снова используется системная схема. */
|
|
43
|
+
setColorSchemeSystem(): Observable<void>;
|
|
44
|
+
private setColorScheme;
|
|
45
|
+
/** Отображает диалоговое окно. */
|
|
46
|
+
showDialog(dialog: Dialog): Observable<void>;
|
|
56
47
|
/**
|
|
57
48
|
* Отображает popover.
|
|
58
49
|
*
|
|
59
50
|
* **source** — элемент, инициировавший открытие (Tab-order, `showPopover({ source })` на клиенте).
|
|
60
51
|
* **anchor** — визуальный якорь (`anchor-name` / `position-anchor`), если отличается от source.
|
|
61
|
-
*
|
|
62
|
-
* @param sourceOrPlacement Один инстанс (source = anchor) или `{ anchor, source }`.
|
|
63
|
-
* @param popover Компонент всплывающего окна.
|
|
64
52
|
*/
|
|
65
|
-
showPopover(source: PopoverShowComponent, popover: Popover): void
|
|
66
|
-
showPopover(placement: PopoverShowPlacement, popover: Popover): void
|
|
67
|
-
showDatePicker(anchor: ComponentInstance | Componentable, ref: ContextValueRef<string | undefined>): void
|
|
68
|
-
showColorPicker(anchor: ComponentInstance | Componentable, ref: ContextValueRef<string | undefined>): void
|
|
69
|
-
showTimePicker(anchor: ComponentInstance | Componentable, ref: ContextValueRef<string | undefined>): void
|
|
70
|
-
showDateTimePicker(anchor: ComponentInstance | Componentable, ref: ContextValueRef<string | undefined>): void
|
|
71
|
-
private
|
|
53
|
+
showPopover(source: PopoverShowComponent, popover: Popover): Observable<void>;
|
|
54
|
+
showPopover(placement: PopoverShowPlacement, popover: Popover): Observable<void>;
|
|
55
|
+
showDatePicker(anchor: ComponentInstance | Componentable, ref: ContextValueRef<string | undefined>): Observable<void>;
|
|
56
|
+
showColorPicker(anchor: ComponentInstance | Componentable, ref: ContextValueRef<string | undefined>): Observable<void>;
|
|
57
|
+
showTimePicker(anchor: ComponentInstance | Componentable, ref: ContextValueRef<string | undefined>): Observable<void>;
|
|
58
|
+
showDateTimePicker(anchor: ComponentInstance | Componentable, ref: ContextValueRef<string | undefined>): Observable<void>;
|
|
59
|
+
private showNativePicker;
|
|
72
60
|
/**
|
|
73
61
|
* Задаёт платформенные оверлеи (anchors + component). Вложенные компоненты участвуют в поиске на сервере;
|
|
74
62
|
* на клиент уходит массив конфигов, как у `properties.overlays` страницы.
|
|
75
63
|
*/
|
|
76
|
-
setOverlays(overlays: Overlay[]): void
|
|
64
|
+
setOverlays(overlays: Overlay[]): Observable<void>;
|
|
77
65
|
/**
|
|
78
66
|
* Текущие платформенные оверлеи (как на странице: anchors + экземпляр component на BFF).
|
|
79
67
|
*/
|
|
80
68
|
getOverlays(): readonly Overlay[];
|
|
81
69
|
/**
|
|
82
70
|
* Запрашивает у клиента список доступных media-устройств (navigator.mediaDevices.enumerateDevices()).
|
|
83
|
-
* Клиент возвращает нормализованный список устройств + capabilities/settings где доступно.
|
|
84
71
|
*
|
|
85
72
|
* Документация: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices
|
|
86
73
|
*/
|
|
87
|
-
enumerateDevices(
|
|
88
|
-
onSuccess: (devices: EnumeratedDeviceInstance[]) => void;
|
|
89
|
-
onError?: (text: string) => void;
|
|
90
|
-
}): void;
|
|
74
|
+
enumerateDevices(): Observable<EnumeratedDeviceInstance[]>;
|
|
91
75
|
}
|
|
92
76
|
/**
|
|
93
77
|
* Инстансы устройств после валидации. Это удобнее сырых объектов:
|
|
@@ -111,4 +95,3 @@ export declare class VideoInputDevice extends PlatformDeviceBase {
|
|
|
111
95
|
}
|
|
112
96
|
export declare class AudioOutputDevice extends PlatformDeviceBase {
|
|
113
97
|
}
|
|
114
|
-
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AudioOutputDevice = exports.VideoInputDevice = exports.AudioInputDevice = exports.Platform = void 0;
|
|
4
|
-
const index_1 = require("@matreshka/shared/messages/bff-to-client/app/index");
|
|
5
4
|
const dialog_show_message_1 = require("@matreshka/shared/messages/bff-to-client/components/dialog/dialog-show-message");
|
|
6
5
|
const popover_show_message_1 = require("@matreshka/shared/messages/bff-to-client/components/popover/popover-show-message");
|
|
7
6
|
const disable_privacy_mode_message_1 = require("@matreshka/shared/messages/bff-to-client/platforms/disable-privacy-mode-message");
|
|
@@ -10,14 +9,22 @@ const platform_enumerate_devices_message_1 = require("@matreshka/shared/messages
|
|
|
10
9
|
const platform_set_color_scheme_message_1 = require("@matreshka/shared/messages/bff-to-client/platforms/platform-set-color-scheme-message");
|
|
11
10
|
const platform_set_overlays_message_1 = require("@matreshka/shared/messages/bff-to-client/platforms/platform-set-overlays-message");
|
|
12
11
|
const platform_show_native_picker_message_1 = require("@matreshka/shared/messages/bff-to-client/platforms/platform-show-native-picker-message");
|
|
13
|
-
const error_message_1 = require("@matreshka/shared/messages/client-to-bff/error-message");
|
|
14
12
|
const platform_enumerate_devices_success_message_1 = require("@matreshka/shared/messages/client-to-bff/platforms/platform-enumerate-devices-success-message");
|
|
15
|
-
const targeted_message_1 = require("@matreshka/shared/messages/targeted-message");
|
|
16
|
-
const rxjs_1 = require("rxjs");
|
|
17
13
|
const v4_1 = require("zod/v4");
|
|
18
14
|
const core_1 = require("../core");
|
|
19
|
-
const incoming_message_observer_1 = require("../core/utils/incoming-message-observer");
|
|
20
15
|
const popover_show_1 = require("./popover-show");
|
|
16
|
+
const client_back_platform_action_1 = require("./utils/client-back-platform-action");
|
|
17
|
+
const client_navigate_platform_action_1 = require("./utils/client-navigate-platform-action");
|
|
18
|
+
const client_reload_platform_action_1 = require("./utils/client-reload-platform-action");
|
|
19
|
+
const targeted_client_platform_action_1 = require("./utils/targeted-client-platform-action");
|
|
20
|
+
const enumeratedDeviceSchema = v4_1.z.strictObject({
|
|
21
|
+
kind: v4_1.z.enum(["audioinput", "audiooutput", "videoinput"]),
|
|
22
|
+
deviceId: v4_1.z.string(),
|
|
23
|
+
groupId: v4_1.z.string(),
|
|
24
|
+
label: v4_1.z.string().optional(),
|
|
25
|
+
capabilities: v4_1.z.record(v4_1.z.string(), v4_1.z.unknown()).optional(),
|
|
26
|
+
settings: v4_1.z.record(v4_1.z.string(), v4_1.z.unknown()).optional(),
|
|
27
|
+
});
|
|
21
28
|
/**
|
|
22
29
|
* Абстрактный класс платформы, управляющий клиентом и его состоянием.
|
|
23
30
|
*/
|
|
@@ -35,62 +42,60 @@ class Platform {
|
|
|
35
42
|
* @param path Путь, по которому необходимо перейти.
|
|
36
43
|
*/
|
|
37
44
|
navigate(path) {
|
|
38
|
-
|
|
45
|
+
return (0, client_navigate_platform_action_1.clientNavigatePlatformAction)(this.client, path);
|
|
39
46
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Переходит на предыдущую страницу в истории навигации клиента.
|
|
42
|
-
*/
|
|
47
|
+
/** Переходит на предыдущую страницу в истории навигации клиента. */
|
|
43
48
|
back() {
|
|
44
|
-
|
|
49
|
+
return (0, client_back_platform_action_1.clientBackPlatformAction)(this.client);
|
|
45
50
|
}
|
|
46
51
|
/**
|
|
47
52
|
* Перезагружает клиентское приложение.
|
|
53
|
+
*
|
|
54
|
+
* Завершение observable — {@link Client.reconnect$} (переподключение WS с тем же token),
|
|
55
|
+
* а не ack с клиента до reload.
|
|
48
56
|
*/
|
|
49
57
|
reload() {
|
|
50
|
-
|
|
58
|
+
return (0, client_reload_platform_action_1.clientReloadPlatformAction)(this.client);
|
|
51
59
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Включает режим конфиденциальности.
|
|
54
|
-
*/
|
|
60
|
+
/** Включает режим конфиденциальности. */
|
|
55
61
|
enablePrivacyMode() {
|
|
56
|
-
this.client
|
|
62
|
+
return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
|
|
63
|
+
outgoingMessage: (scope) => new enable_privacy_mode_message_1.EnablePrivacyModeMessage(scope),
|
|
64
|
+
});
|
|
57
65
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Отключает режим конфиденциальности.
|
|
60
|
-
*/
|
|
66
|
+
/** Отключает режим конфиденциальности. */
|
|
61
67
|
disablePrivacyMode() {
|
|
62
|
-
this.client
|
|
68
|
+
return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
|
|
69
|
+
outgoingMessage: (scope) => new disable_privacy_mode_message_1.DisablePrivacyModeMessage(scope),
|
|
70
|
+
});
|
|
63
71
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Явно включает светлую цветовую схему на клиенте.
|
|
66
|
-
*/
|
|
72
|
+
/** Явно включает светлую цветовую схему на клиенте. */
|
|
67
73
|
setColorSchemeLight() {
|
|
68
|
-
this.
|
|
74
|
+
return this.setColorScheme("light");
|
|
69
75
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Явно включает тёмную цветовую схему на клиенте.
|
|
72
|
-
*/
|
|
76
|
+
/** Явно включает тёмную цветовую схему на клиенте. */
|
|
73
77
|
setColorSchemeDark() {
|
|
74
|
-
this.
|
|
78
|
+
return this.setColorScheme("dark");
|
|
75
79
|
}
|
|
76
|
-
/**
|
|
77
|
-
* Сбрасывает выбор темы: снова используется системная схема.
|
|
78
|
-
*/
|
|
80
|
+
/** Сбрасывает выбор темы: снова используется системная схема. */
|
|
79
81
|
setColorSchemeSystem() {
|
|
80
|
-
this.
|
|
82
|
+
return this.setColorScheme("system");
|
|
81
83
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
setColorScheme(mode) {
|
|
85
|
+
return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
|
|
86
|
+
outgoingMessage: (scope) => new platform_set_color_scheme_message_1.PlatformSetColorSchemeMessage(scope, { mode }),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/** Отображает диалоговое окно. */
|
|
87
90
|
showDialog(dialog) {
|
|
88
91
|
const serializedDialog = dialog.serialize();
|
|
89
|
-
this.client
|
|
92
|
+
return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
|
|
93
|
+
outgoingMessage: (scope) => new dialog_show_message_1.DialogShowMessage(scope, serializedDialog),
|
|
94
|
+
});
|
|
90
95
|
}
|
|
91
96
|
showPopover(sourceOrPlacement, popover) {
|
|
92
97
|
const serializedPopover = popover.serialize();
|
|
93
|
-
const
|
|
98
|
+
const wirePayload = (0, popover_show_1.isPopoverShowPlacement)(sourceOrPlacement)
|
|
94
99
|
? {
|
|
95
100
|
source: sourceOrPlacement.source.id,
|
|
96
101
|
anchor: sourceOrPlacement.anchor.id,
|
|
@@ -100,26 +105,30 @@ class Platform {
|
|
|
100
105
|
source: sourceOrPlacement.id,
|
|
101
106
|
popover: serializedPopover,
|
|
102
107
|
};
|
|
103
|
-
this.client
|
|
108
|
+
return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
|
|
109
|
+
outgoingMessage: (scope) => new popover_show_message_1.PopoverShowMessage(scope, wirePayload),
|
|
110
|
+
});
|
|
104
111
|
}
|
|
105
112
|
showDatePicker(anchor, ref) {
|
|
106
|
-
this.
|
|
113
|
+
return this.showNativePicker(anchor, "date", ref);
|
|
107
114
|
}
|
|
108
115
|
showColorPicker(anchor, ref) {
|
|
109
|
-
this.
|
|
116
|
+
return this.showNativePicker(anchor, "color", ref);
|
|
110
117
|
}
|
|
111
118
|
showTimePicker(anchor, ref) {
|
|
112
|
-
this.
|
|
119
|
+
return this.showNativePicker(anchor, "time", ref);
|
|
113
120
|
}
|
|
114
121
|
showDateTimePicker(anchor, ref) {
|
|
115
|
-
this.
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
this.client
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
return this.showNativePicker(anchor, "datetime-local", ref);
|
|
123
|
+
}
|
|
124
|
+
showNativePicker(anchor, inputType, ref) {
|
|
125
|
+
return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
|
|
126
|
+
outgoingMessage: (scope) => new platform_show_native_picker_message_1.PlatformShowNativePickerMessage(scope, {
|
|
127
|
+
component_id: anchor.id,
|
|
128
|
+
inputType,
|
|
129
|
+
ref: ref.toJSON(),
|
|
130
|
+
}),
|
|
131
|
+
});
|
|
123
132
|
}
|
|
124
133
|
/**
|
|
125
134
|
* Задаёт платформенные оверлеи (anchors + component). Вложенные компоненты участвуют в поиске на сервере;
|
|
@@ -130,9 +139,11 @@ class Platform {
|
|
|
130
139
|
this.client.removeGlobalComponent(o.component);
|
|
131
140
|
}
|
|
132
141
|
this.platformOverlays = [...overlays];
|
|
133
|
-
this.client
|
|
134
|
-
|
|
135
|
-
|
|
142
|
+
return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
|
|
143
|
+
outgoingMessage: (scope) => new platform_set_overlays_message_1.PlatformSetOverlaysMessage(scope, {
|
|
144
|
+
overlays: (0, core_1.runWithEntry)(this.client.ensureAppOverlayEntry(), () => (0, core_1.serializeOverlays)(this.platformOverlays)),
|
|
145
|
+
}),
|
|
146
|
+
});
|
|
136
147
|
}
|
|
137
148
|
/**
|
|
138
149
|
* Текущие платформенные оверлеи (как на странице: anchors + экземпляр component на BFF).
|
|
@@ -142,44 +153,23 @@ class Platform {
|
|
|
142
153
|
}
|
|
143
154
|
/**
|
|
144
155
|
* Запрашивает у клиента список доступных media-устройств (navigator.mediaDevices.enumerateDevices()).
|
|
145
|
-
* Клиент возвращает нормализованный список устройств + capabilities/settings где доступно.
|
|
146
156
|
*
|
|
147
157
|
* Документация: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices
|
|
148
158
|
*/
|
|
149
|
-
enumerateDevices(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const successPayloadSchema = v4_1.z.strictObject({
|
|
161
|
-
devices: v4_1.z.array(deviceSchema),
|
|
162
|
-
});
|
|
163
|
-
const errorPayloadSchema = v4_1.z.strictObject({
|
|
164
|
-
message: v4_1.z.string(),
|
|
165
|
-
});
|
|
166
|
-
const subscription = this.client.incomingMessage$
|
|
167
|
-
.pipe((0, rxjs_1.filter)((unsafeMessage) => (0, targeted_message_1.isTargetedMessage)(unsafeMessage) && unsafeMessage.target === scope))
|
|
168
|
-
.subscribe((0, incoming_message_observer_1.incomingMessageObserver)(this.client, (unsafeMessage) => {
|
|
169
|
-
subscription.unsubscribe();
|
|
170
|
-
if (unsafeMessage instanceof platform_enumerate_devices_success_message_1.PlatformEnumerateDevicesSuccessMessage) {
|
|
171
|
-
const payload = successPayloadSchema.parse(unsafeMessage.payload);
|
|
172
|
-
config.onSuccess(payload.devices.map((d) => toDeviceInstance(d)));
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
if (unsafeMessage instanceof error_message_1.ErrorMessage) {
|
|
176
|
-
const payload = errorPayloadSchema.parse(unsafeMessage.payload);
|
|
177
|
-
if (typeof config.onError === "function") {
|
|
178
|
-
config.onError(payload.message);
|
|
159
|
+
enumerateDevices() {
|
|
160
|
+
return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
|
|
161
|
+
outgoingMessage: (scope) => new platform_enumerate_devices_message_1.PlatformEnumerateDevicesMessage(scope),
|
|
162
|
+
parseSuccess: (unsafeMessage) => {
|
|
163
|
+
if (unsafeMessage instanceof platform_enumerate_devices_success_message_1.PlatformEnumerateDevicesSuccessMessage) {
|
|
164
|
+
const payload = v4_1.z
|
|
165
|
+
.strictObject({
|
|
166
|
+
devices: v4_1.z.array(enumeratedDeviceSchema),
|
|
167
|
+
})
|
|
168
|
+
.parse(unsafeMessage.payload);
|
|
169
|
+
return payload.devices.map((d) => toDeviceInstance(d));
|
|
179
170
|
}
|
|
180
|
-
}
|
|
181
|
-
})
|
|
182
|
-
this.client.outcomingMessage$.next(new platform_enumerate_devices_message_1.PlatformEnumerateDevicesMessage(scope));
|
|
171
|
+
},
|
|
172
|
+
});
|
|
183
173
|
}
|
|
184
174
|
}
|
|
185
175
|
exports.Platform = Platform;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Observable } from "rxjs";
|
|
1
2
|
import { z } from "zod/v4";
|
|
2
3
|
import { WebPlatform } from "./web-platform";
|
|
3
4
|
/**
|
|
@@ -9,6 +10,17 @@ declare const requestContactSuccessMessageSchema: z.ZodObject<{
|
|
|
9
10
|
last_name: z.ZodOptional<z.ZodString>;
|
|
10
11
|
user_id: z.ZodNumber;
|
|
11
12
|
}, z.core.$strict>;
|
|
13
|
+
declare const telegramGeolocationSuccessSchema: z.ZodObject<{
|
|
14
|
+
latitude: z.ZodNumber;
|
|
15
|
+
longitude: z.ZodNumber;
|
|
16
|
+
altitude: z.ZodNullable<z.ZodNumber>;
|
|
17
|
+
course: z.ZodNullable<z.ZodNumber>;
|
|
18
|
+
speed: z.ZodNullable<z.ZodNumber>;
|
|
19
|
+
horizontal_accuracy: z.ZodNullable<z.ZodNumber>;
|
|
20
|
+
vertical_accuracy: z.ZodNullable<z.ZodNumber>;
|
|
21
|
+
course_accuracy: z.ZodNullable<z.ZodNumber>;
|
|
22
|
+
speed_accuracy: z.ZodNullable<z.ZodNumber>;
|
|
23
|
+
}, z.core.$strict>;
|
|
12
24
|
type TelegramWebAppUser = {
|
|
13
25
|
id: number;
|
|
14
26
|
is_bot?: boolean;
|
|
@@ -43,45 +55,15 @@ type TelegramWebAppInitData = {
|
|
|
43
55
|
* Платформа для Telegram Mini App.
|
|
44
56
|
*/
|
|
45
57
|
export declare class TelegramMiniAppPlatform extends WebPlatform {
|
|
46
|
-
|
|
47
|
-
* Инициирует загрузку файла по указанному URL.
|
|
48
|
-
*
|
|
49
|
-
* @param url Ссылка на файл.
|
|
50
|
-
* @param filename Имя файла для сохранения.
|
|
51
|
-
*/
|
|
52
|
-
downloadFile(url: string, filename: string): void;
|
|
53
|
-
/**
|
|
54
|
-
* Делится содержимым через системное диалоговое окно обмена.
|
|
55
|
-
*
|
|
56
|
-
* @param data Объект с текстом, ссылкой и/или заголовком.
|
|
57
|
-
*/
|
|
58
|
+
downloadFile(url: string, filename: string): Observable<void>;
|
|
58
59
|
share(data: {
|
|
59
60
|
url?: string;
|
|
60
61
|
title?: string;
|
|
61
62
|
text?: string;
|
|
62
|
-
}): void
|
|
63
|
+
}): Observable<void>;
|
|
63
64
|
initData(botToken: string): TelegramWebAppInitData;
|
|
64
65
|
private verifyTelegramWebAppData;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
*
|
|
68
|
-
* @param config Объект с обработчиками успешного получения геолокации и отмены.
|
|
69
|
-
*/
|
|
70
|
-
getGeolocation(config: {
|
|
71
|
-
onSuccess: (position: {
|
|
72
|
-
latitude: number;
|
|
73
|
-
longitude: number;
|
|
74
|
-
}) => void;
|
|
75
|
-
onError?: (error: string) => void;
|
|
76
|
-
}): void;
|
|
77
|
-
/**
|
|
78
|
-
* Запрашивает контактные данные пользователя в Telegram Mini App.
|
|
79
|
-
*
|
|
80
|
-
* @param config Объект с обработчиками успешного получения контакта и отмены.
|
|
81
|
-
*/
|
|
82
|
-
requestContact(config: {
|
|
83
|
-
onReceive: (data: z.infer<typeof requestContactSuccessMessageSchema>) => void;
|
|
84
|
-
onCancel?: () => void;
|
|
85
|
-
}): void;
|
|
66
|
+
getGeolocation(): Observable<z.infer<typeof telegramGeolocationSuccessSchema>>;
|
|
67
|
+
requestContact(): Observable<z.infer<typeof requestContactSuccessMessageSchema>>;
|
|
86
68
|
}
|
|
87
69
|
export {};
|
|
@@ -8,15 +8,12 @@ const telegram_mini_app_download_file_message_1 = require("@matreshka/shared/mes
|
|
|
8
8
|
const telegram_mini_app_get_geolocation_message_1 = require("@matreshka/shared/messages/bff-to-client/platforms/telegram-mini-app/telegram-mini-app-get-geolocation-message");
|
|
9
9
|
const telegram_mini_app_request_contact_message_1 = require("@matreshka/shared/messages/bff-to-client/platforms/telegram-mini-app/telegram-mini-app-request-contact-message");
|
|
10
10
|
const telegram_mini_app_share_message_1 = require("@matreshka/shared/messages/bff-to-client/platforms/telegram-mini-app/telegram-mini-app-share-message");
|
|
11
|
-
const error_message_1 = require("@matreshka/shared/messages/client-to-bff/error-message");
|
|
12
11
|
const telegram_mini_app_get_geolocation_success_message_1 = require("@matreshka/shared/messages/client-to-bff/platforms/telegram-mini-app/telegram-mini-app-get-geolocation-success-message");
|
|
13
12
|
const telegram_mini_app_request_contact_action_cancel_message_1 = require("@matreshka/shared/messages/client-to-bff/platforms/telegram-mini-app/telegram-mini-app-request-contact-action-cancel-message");
|
|
14
13
|
const telegram_mini_app_request_contact_action_success_message_1 = require("@matreshka/shared/messages/client-to-bff/platforms/telegram-mini-app/telegram-mini-app-request-contact-action-success-message");
|
|
15
|
-
const targeted_message_1 = require("@matreshka/shared/messages/targeted-message");
|
|
16
14
|
const crypto_1 = __importDefault(require("crypto"));
|
|
17
|
-
const rxjs_1 = require("rxjs");
|
|
18
15
|
const v4_1 = require("zod/v4");
|
|
19
|
-
const
|
|
16
|
+
const targeted_client_platform_action_1 = require("./utils/targeted-client-platform-action");
|
|
20
17
|
const web_platform_1 = require("./web-platform");
|
|
21
18
|
/**
|
|
22
19
|
* Входящее сообщение с данными пользователя после успешного запроса контакта.
|
|
@@ -27,26 +24,30 @@ const requestContactSuccessMessageSchema = v4_1.z.strictObject({
|
|
|
27
24
|
last_name: v4_1.z.string().optional(),
|
|
28
25
|
user_id: v4_1.z.number(),
|
|
29
26
|
});
|
|
27
|
+
const telegramGeolocationSuccessSchema = v4_1.z.strictObject({
|
|
28
|
+
latitude: v4_1.z.number(),
|
|
29
|
+
longitude: v4_1.z.number(),
|
|
30
|
+
altitude: v4_1.z.number().nullable(),
|
|
31
|
+
course: v4_1.z.number().nullable(),
|
|
32
|
+
speed: v4_1.z.number().nullable(),
|
|
33
|
+
horizontal_accuracy: v4_1.z.number().nullable(),
|
|
34
|
+
vertical_accuracy: v4_1.z.number().nullable(),
|
|
35
|
+
course_accuracy: v4_1.z.number().nullable(),
|
|
36
|
+
speed_accuracy: v4_1.z.number().nullable(),
|
|
37
|
+
});
|
|
30
38
|
/**
|
|
31
39
|
* Платформа для Telegram Mini App.
|
|
32
40
|
*/
|
|
33
41
|
class TelegramMiniAppPlatform extends web_platform_1.WebPlatform {
|
|
34
|
-
/**
|
|
35
|
-
* Инициирует загрузку файла по указанному URL.
|
|
36
|
-
*
|
|
37
|
-
* @param url Ссылка на файл.
|
|
38
|
-
* @param filename Имя файла для сохранения.
|
|
39
|
-
*/
|
|
40
42
|
downloadFile(url, filename) {
|
|
41
|
-
|
|
43
|
+
return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
|
|
44
|
+
outgoingMessage: (scope) => new telegram_mini_app_download_file_message_1.TelegramMiniAppDownloadFileMessage(scope, { url, filename }),
|
|
45
|
+
});
|
|
42
46
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Делится содержимым через системное диалоговое окно обмена.
|
|
45
|
-
*
|
|
46
|
-
* @param data Объект с текстом, ссылкой и/или заголовком.
|
|
47
|
-
*/
|
|
48
47
|
share(data) {
|
|
49
|
-
this.client
|
|
48
|
+
return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
|
|
49
|
+
outgoingMessage: (scope) => new telegram_mini_app_share_message_1.TelegramMiniAppShareMessage(scope, data),
|
|
50
|
+
});
|
|
50
51
|
}
|
|
51
52
|
initData(botToken) {
|
|
52
53
|
const initDataString = this.client.state$.getValue().platform
|
|
@@ -55,9 +56,6 @@ class TelegramMiniAppPlatform extends web_platform_1.WebPlatform {
|
|
|
55
56
|
if (verified) {
|
|
56
57
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
57
58
|
const res = Object.fromEntries(new URLSearchParams(initDataString));
|
|
58
|
-
// if (res.user) {
|
|
59
|
-
// res.user = JSON.parse(res.user);
|
|
60
|
-
// }
|
|
61
59
|
return {
|
|
62
60
|
...res,
|
|
63
61
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
@@ -73,95 +71,46 @@ class TelegramMiniAppPlatform extends web_platform_1.WebPlatform {
|
|
|
73
71
|
}
|
|
74
72
|
}
|
|
75
73
|
verifyTelegramWebAppData(telegramInitData, botToken) {
|
|
76
|
-
// The data is a query string, which is composed of a series of field-value pairs.
|
|
77
74
|
const encoded = decodeURIComponent(telegramInitData);
|
|
78
|
-
// HMAC-SHA-256 signature of the bot's token with the constant string WebAppData used as a key.
|
|
79
75
|
const secret = crypto_1.default.createHmac("sha256", "WebAppData").update(botToken);
|
|
80
|
-
// Data-check-string is a chain of all received fields'.
|
|
81
76
|
const arr = encoded.split("&");
|
|
82
77
|
const hashIndex = arr.findIndex((str) => str.startsWith("hash="));
|
|
83
78
|
const hash = arr.splice(hashIndex, 1)[0].split("=")[1];
|
|
84
|
-
// sorted alphabetically
|
|
85
79
|
arr.sort((a, b) => a.localeCompare(b));
|
|
86
|
-
// in the format key=<value> with a line feed character ('\n', 0x0A) used as separator
|
|
87
|
-
// e.g., 'auth_date=<auth_date>\nquery_id=<query_id>\nuser=<user>
|
|
88
80
|
const dataCheckString = arr.join("\n");
|
|
89
|
-
// The hexadecimal representation of the HMAC-SHA-256 signature of the data-check-string with the secret key
|
|
90
81
|
const secretHex = secret.digest("hex");
|
|
91
82
|
const _hash = crypto_1.default
|
|
92
83
|
.createHmac("sha256", secretHex)
|
|
93
84
|
.update(dataCheckString)
|
|
94
85
|
.digest("hex");
|
|
95
|
-
// if hash are equal the data may be used on your server.
|
|
96
|
-
// Complex data types are represented as JSON-serialized objects.
|
|
97
86
|
return _hash === hash;
|
|
98
87
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const scope = "platform-action-" + crypto_1.default.randomUUID();
|
|
106
|
-
const subscription = this.client.incomingMessage$
|
|
107
|
-
.pipe((0, rxjs_1.filter)((unsafeMessage) => (0, targeted_message_1.isTargetedMessage)(unsafeMessage) && unsafeMessage.target === scope))
|
|
108
|
-
.subscribe((0, incoming_message_observer_1.incomingMessageObserver)(this.client, (unsafeMessage) => {
|
|
109
|
-
subscription.unsubscribe();
|
|
110
|
-
if (unsafeMessage instanceof telegram_mini_app_get_geolocation_success_message_1.TelegramMiniAppGetGeolocationSuccessMessage) {
|
|
111
|
-
const messagePayload = v4_1.z
|
|
112
|
-
.strictObject({
|
|
113
|
-
latitude: v4_1.z.number(),
|
|
114
|
-
longitude: v4_1.z.number(),
|
|
115
|
-
altitude: v4_1.z.number().nullable(),
|
|
116
|
-
course: v4_1.z.number().nullable(),
|
|
117
|
-
speed: v4_1.z.number().nullable(),
|
|
118
|
-
horizontal_accuracy: v4_1.z.number().nullable(),
|
|
119
|
-
vertical_accuracy: v4_1.z.number().nullable(),
|
|
120
|
-
course_accuracy: v4_1.z.number().nullable(),
|
|
121
|
-
speed_accuracy: v4_1.z.number().nullable(),
|
|
122
|
-
})
|
|
123
|
-
.parse(unsafeMessage.payload);
|
|
124
|
-
config.onSuccess(messagePayload);
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
if (unsafeMessage instanceof error_message_1.ErrorMessage) {
|
|
128
|
-
const messagePayload = v4_1.z
|
|
129
|
-
.strictObject({
|
|
130
|
-
message: v4_1.z.string(),
|
|
131
|
-
})
|
|
132
|
-
.parse(unsafeMessage.payload);
|
|
133
|
-
if (typeof config.onError === "function") {
|
|
134
|
-
config.onError(messagePayload.message);
|
|
88
|
+
getGeolocation() {
|
|
89
|
+
return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
|
|
90
|
+
outgoingMessage: (scope) => new telegram_mini_app_get_geolocation_message_1.TelegramMiniAppGetGeolocationMessage(scope),
|
|
91
|
+
parseSuccess: (unsafeMessage) => {
|
|
92
|
+
if (unsafeMessage instanceof telegram_mini_app_get_geolocation_success_message_1.TelegramMiniAppGetGeolocationSuccessMessage) {
|
|
93
|
+
return telegramGeolocationSuccessSchema.parse(unsafeMessage.payload);
|
|
135
94
|
}
|
|
136
|
-
}
|
|
137
|
-
})
|
|
138
|
-
this.client.outcomingMessage$.next(new telegram_mini_app_get_geolocation_message_1.TelegramMiniAppGetGeolocationMessage(scope));
|
|
95
|
+
},
|
|
96
|
+
});
|
|
139
97
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const messagePayload = requestContactSuccessMessageSchema.parse(unsafeMessage.payload);
|
|
154
|
-
config.onReceive(messagePayload);
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
if (unsafeMessage instanceof
|
|
158
|
-
telegram_mini_app_request_contact_action_cancel_message_1.TelegramMiniAppRequestContactActionCancelMessage) {
|
|
159
|
-
if ("onCancel" in config) {
|
|
160
|
-
config.onCancel();
|
|
98
|
+
requestContact() {
|
|
99
|
+
return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
|
|
100
|
+
outgoingMessage: (scope) => new telegram_mini_app_request_contact_message_1.TelegramMiniAppRequestContactMessage(scope),
|
|
101
|
+
parseSuccess: (unsafeMessage) => {
|
|
102
|
+
if (unsafeMessage instanceof
|
|
103
|
+
telegram_mini_app_request_contact_action_success_message_1.TelegramMiniAppRequestContactActionSuccessMessage) {
|
|
104
|
+
return requestContactSuccessMessageSchema.parse(unsafeMessage.payload);
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
parseFailure: (unsafeMessage) => {
|
|
108
|
+
if (unsafeMessage instanceof
|
|
109
|
+
telegram_mini_app_request_contact_action_cancel_message_1.TelegramMiniAppRequestContactActionCancelMessage) {
|
|
110
|
+
return new Error("User cancelled contact request");
|
|
161
111
|
}
|
|
162
|
-
}
|
|
163
|
-
})
|
|
164
|
-
this.client.outcomingMessage$.next(new telegram_mini_app_request_contact_message_1.TelegramMiniAppRequestContactMessage(scope));
|
|
112
|
+
},
|
|
113
|
+
});
|
|
165
114
|
}
|
|
166
115
|
}
|
|
167
116
|
exports.TelegramMiniAppPlatform = TelegramMiniAppPlatform;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
|
+
import { Client } from "../../core";
|
|
3
|
+
/**
|
|
4
|
+
* Back без targeted ack с клиента (как {@link clientNavigatePlatformAction}).
|
|
5
|
+
*
|
|
6
|
+
* Завершение: новый `route.visitedAt`, {@link AppPageMessage} и receipt.
|
|
7
|
+
* Timeout нет; при {@link Client.destroy$} до завершения — error.
|
|
8
|
+
*/
|
|
9
|
+
export declare function clientBackPlatformAction(client: Client): Observable<void>;
|