@matreshka/bff 0.16.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.
Files changed (47) hide show
  1. package/dist/components/board.d.ts +0 -3
  2. package/dist/components/board.js +3 -11
  3. package/dist/components/camera.d.ts +0 -3
  4. package/dist/components/camera.js +4 -11
  5. package/dist/components/component.d.ts +17 -1
  6. package/dist/components/component.js +19 -2
  7. package/dist/components/container.js +8 -11
  8. package/dist/components/dialog.d.ts +0 -3
  9. package/dist/components/dialog.js +4 -11
  10. package/dist/components/file-upload-area.js +8 -11
  11. package/dist/components/form.js +8 -11
  12. package/dist/components/grid.js +7 -11
  13. package/dist/components/map.d.ts +0 -3
  14. package/dist/components/map.js +2 -12
  15. package/dist/components/page.d.ts +0 -1
  16. package/dist/components/page.js +4 -10
  17. package/dist/components/popover.d.ts +0 -3
  18. package/dist/components/popover.js +4 -11
  19. package/dist/components/stack.d.ts +2 -5
  20. package/dist/components/stack.js +4 -11
  21. package/dist/core/utils/serialize-component-tree.d.ts +3 -0
  22. package/dist/core/utils/serialize-component-tree.js +21 -0
  23. package/dist/platforms/browser-platform.d.ts +21 -37
  24. package/dist/platforms/browser-platform.js +61 -104
  25. package/dist/platforms/max-mini-app-platform.d.ts +2 -8
  26. package/dist/platforms/max-mini-app-platform.js +10 -21
  27. package/dist/platforms/mobile-platform.d.ts +32 -58
  28. package/dist/platforms/mobile-platform.js +139 -211
  29. package/dist/platforms/platform.d.ts +32 -49
  30. package/dist/platforms/platform.js +77 -87
  31. package/dist/platforms/telegram-mini-app-platform.d.ts +16 -34
  32. package/dist/platforms/telegram-mini-app-platform.js +41 -92
  33. package/dist/platforms/utils/client-back-platform-action.d.ts +9 -0
  34. package/dist/platforms/utils/client-back-platform-action.js +48 -0
  35. package/dist/platforms/utils/client-navigate-platform-action.d.ts +19 -0
  36. package/dist/platforms/utils/client-navigate-platform-action.js +60 -0
  37. package/dist/platforms/utils/client-reload-platform-action.d.ts +8 -0
  38. package/dist/platforms/utils/client-reload-platform-action.js +41 -0
  39. package/dist/platforms/utils/client-route-page-wait.d.ts +11 -0
  40. package/dist/platforms/utils/client-route-page-wait.js +33 -0
  41. package/dist/platforms/utils/match-navigate-path.d.ts +11 -0
  42. package/dist/platforms/utils/match-navigate-path.js +95 -0
  43. package/dist/platforms/utils/targeted-client-platform-action.d.ts +11 -0
  44. package/dist/platforms/utils/targeted-client-platform-action.js +80 -0
  45. package/dist/platforms/utils/targeted-client-platform-stream.d.ts +17 -0
  46. package/dist/platforms/utils/targeted-client-platform-stream.js +90 -0
  47. package/package.json +2 -2
@@ -81,7 +81,6 @@ class Stack extends component_1.Component {
81
81
  padding: initValues.padding,
82
82
  scroll: initValues.scroll,
83
83
  safeArea: initValues.safeArea,
84
- overlays: initValues.overlays,
85
84
  surface: initValues.surface,
86
85
  outline: initValues.outline,
87
86
  focusWithinStyle: initValues.focusWithinStyle,
@@ -124,13 +123,10 @@ class Stack extends component_1.Component {
124
123
  return this;
125
124
  }
126
125
  serializeRuleOverrides(overrides) {
127
- const out = { ...overrides };
126
+ const out = super.serializeRuleOverrides(overrides);
128
127
  if (overrides.content !== undefined) {
129
128
  out.content = (0, core_1.serializeComponentList)(overrides.content);
130
129
  }
131
- if (overrides.overlays !== undefined) {
132
- out.overlays = (0, core_1.serializeOverlays)(overrides.overlays);
133
- }
134
130
  if (overrides.flexItem !== undefined) {
135
131
  out.flexItem = (0, flex_item_1.normalizeFlexItem)(overrides.flexItem);
136
132
  }
@@ -138,15 +134,12 @@ class Stack extends component_1.Component {
138
134
  }
139
135
  serialize(instance) {
140
136
  const result = super.serialize(instance);
141
- const p = this.properties;
142
137
  return {
143
138
  ...result,
144
139
  class: server_component_class_1.ServerComponentClass.Stack,
145
- properties: {
146
- ...p,
147
- content: (0, core_1.serializeComponentList)(p.content),
148
- overlays: p.overlays ? (0, core_1.serializeOverlays)(p.overlays) : [],
149
- },
140
+ properties: this.buildPropertiesForClient({
141
+ content: (0, core_1.serializeComponentList)(this.properties.content),
142
+ }),
150
143
  };
151
144
  }
152
145
  }
@@ -5,5 +5,8 @@ import { type ComponentTreeNode } from "../types/component-tree-node";
5
5
  export type SerializedComponentPayload = ServerComponentConfig;
6
6
  export declare function serializeComponentList(components: readonly ComponentTreeNode[]): SerializedComponentPayload[];
7
7
  export declare function serializeOverlays(overlays: readonly Overlay[]): SharedOverlay<ServerComponentConfig>[];
8
+ /** Сериализует overlays для клиента; при отсутствии или пустом массиве — `undefined` (ключ не попадает в JSON). */
9
+ export declare function serializeOverlaysProperty(overlays: readonly Overlay[] | undefined): SharedOverlay<ServerComponentConfig>[] | undefined;
10
+ export declare function assignSerializedOverlays(out: Record<string, unknown>, overlays: readonly Overlay[] | undefined): void;
8
11
  export declare function serializeForEachSlot(slot: ComponentTreeNode | ComponentTreeNode[]): SerializedComponentPayload | SerializedComponentPayload[];
9
12
  export declare function serializeForEachSlots(slots: (ComponentTreeNode | ComponentTreeNode[])[]): Array<SerializedComponentPayload | SerializedComponentPayload[]>;
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.serializeComponentList = serializeComponentList;
4
4
  exports.serializeOverlays = serializeOverlays;
5
+ exports.serializeOverlaysProperty = serializeOverlaysProperty;
6
+ exports.assignSerializedOverlays = assignSerializedOverlays;
5
7
  exports.serializeForEachSlot = serializeForEachSlot;
6
8
  exports.serializeForEachSlots = serializeForEachSlots;
7
9
  function serializeComponentList(components) {
@@ -13,6 +15,25 @@ function serializeOverlays(overlays) {
13
15
  component: o.component.serialize(),
14
16
  }));
15
17
  }
18
+ /** Сериализует overlays для клиента; при отсутствии или пустом массиве — `undefined` (ключ не попадает в JSON). */
19
+ function serializeOverlaysProperty(overlays) {
20
+ if (!overlays?.length) {
21
+ return undefined;
22
+ }
23
+ return serializeOverlays(overlays);
24
+ }
25
+ function assignSerializedOverlays(out, overlays) {
26
+ if (overlays === undefined) {
27
+ return;
28
+ }
29
+ const serialized = serializeOverlaysProperty(overlays);
30
+ if (serialized !== undefined) {
31
+ out.overlays = serialized;
32
+ }
33
+ else {
34
+ delete out.overlays;
35
+ }
36
+ }
16
37
  function serializeForEachSlot(slot) {
17
38
  if (Array.isArray(slot)) {
18
39
  return serializeComponentList(slot);
@@ -1,4 +1,5 @@
1
1
  import type { AuthenticationResponseJSON, PublicKeyCredentialCreationOptionsJSON, PublicKeyCredentialRequestOptionsJSON, RegistrationResponseJSON } from "@simplewebauthn/types";
2
+ import type { Observable } from "rxjs";
2
3
  import { WebPlatform } from "./web-platform";
3
4
  /**
4
5
  * Платформа для браузерной версии клиента.
@@ -9,15 +10,11 @@ export declare class BrowserPlatform extends WebPlatform {
9
10
  /**
10
11
  * Запрашивает геолокацию пользователя в веб-клиенте.
11
12
  *
12
- * @param config Объект с обработчиками успешного получения геолокации и отмены.
13
13
  */
14
- getGeolocation(config: {
15
- onSuccess: (position: {
16
- latitude: number;
17
- longitude: number;
18
- }) => void;
19
- onError?: (error: string) => void;
20
- }): void;
14
+ getGeolocation(): Observable<{
15
+ latitude: number;
16
+ longitude: number;
17
+ }>;
21
18
  /**
22
19
  * Добавляет событие в календарь клиента.
23
20
  *
@@ -29,27 +26,27 @@ export declare class BrowserPlatform extends WebPlatform {
29
26
  summary: string;
30
27
  location?: string;
31
28
  description?: string;
32
- }): void;
29
+ }): Observable<void>;
33
30
  /**
34
31
  * Сохраняет CSV-файл на устройстве пользователя.
35
32
  *
36
33
  * @param filename Имя файла (будет добавлено расширение `.csv`, если не указано).
37
34
  * @param content Двумерный массив строк, представляющий содержимое CSV.
38
35
  */
39
- downloadCsvContent(filename: string, content: string[][]): void;
36
+ downloadCsvContent(filename: string, content: string[][]): Observable<void>;
40
37
  /**
41
38
  * Инициирует загрузку файла по указанному URL.
42
39
  *
43
40
  * @param url Ссылка на файл.
44
41
  * @param filename Имя сохраняемого файла.
45
42
  */
46
- downloadFile(url: string, filename: string): void;
43
+ downloadFile(url: string, filename: string): Observable<void>;
47
44
  /**
48
45
  * Открывает файл во встроенном просмотрщике браузера (PDF, изображения и т.д.).
49
46
  *
50
47
  * @param url Ссылка на файл (blob: или HTTP).
51
48
  */
52
- openFile(url: string): void;
49
+ openFile(url: string): Observable<void>;
53
50
  /**
54
51
  * Делится содержимым через системное диалоговое окно обмена.
55
52
  *
@@ -59,42 +56,29 @@ export declare class BrowserPlatform extends WebPlatform {
59
56
  url?: string;
60
57
  title?: string;
61
58
  text?: string;
62
- }): void;
59
+ }): Observable<void>;
63
60
  /**
64
61
  * Запрашивает разрешение на push-уведомления и обрабатывает результат.
65
62
  *
66
- * @param config Объект с колбэками: `onGranted` при успехе, `onError` при ошибке.
63
+ * @param publicKey Публичный VAPID-ключ для подписки в браузере.
67
64
  */
68
- registerPushNotifications(config: {
69
- publicKey: string;
70
- onGranted: (subscription: {
71
- endpoint: string;
72
- expirationTime?: EpochTimeStamp | null;
73
- keys: {
74
- auth: string;
75
- p256dh: string;
76
- };
77
- }) => void;
78
- onError?: (text: string) => void;
79
- }): void;
65
+ registerPushNotifications(publicKey: string): Observable<{
66
+ endpoint: string;
67
+ expirationTime?: EpochTimeStamp | null;
68
+ keys: {
69
+ auth: string;
70
+ p256dh: string;
71
+ };
72
+ }>;
80
73
  /**
81
74
  * Регистрация WebAuthn credential (passkey / security key) в браузерном клиенте.
82
75
  *
83
76
  * @remarks Только `BrowserPlatform` / `PwaPlatform`. Mobile — не поддерживается.
84
77
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API
85
78
  */
86
- createWebAuthnCredential(config: {
87
- optionsJSON: PublicKeyCredentialCreationOptionsJSON;
88
- onSuccess: (credentialJSON: RegistrationResponseJSON) => void;
89
- onError?: (text: string) => void;
90
- }): void;
79
+ createWebAuthnCredential(optionsJSON: PublicKeyCredentialCreationOptionsJSON): Observable<RegistrationResponseJSON>;
91
80
  /**
92
81
  * Аутентификация через WebAuthn credential в браузерном клиенте.
93
82
  */
94
- getWebAuthnCredential(config: {
95
- optionsJSON: PublicKeyCredentialRequestOptionsJSON;
96
- onSuccess: (credentialJSON: AuthenticationResponseJSON) => void;
97
- onError?: (text: string) => void;
98
- }): void;
99
- private runWebAuthnPlatformAction;
83
+ getWebAuthnCredential(optionsJSON: PublicKeyCredentialRequestOptionsJSON): Observable<AuthenticationResponseJSON>;
100
84
  }
@@ -10,15 +10,12 @@ const browser_request_push_notifications_message_1 = require("@matreshka/shared/
10
10
  const browser_share_message_1 = require("@matreshka/shared/messages/bff-to-client/platforms/browser/browser-share-message");
11
11
  const platform_webauthn_create_credential_message_1 = require("@matreshka/shared/messages/bff-to-client/platforms/platform-webauthn-create-credential-message");
12
12
  const platform_webauthn_get_credential_message_1 = require("@matreshka/shared/messages/bff-to-client/platforms/platform-webauthn-get-credential-message");
13
- const error_message_1 = require("@matreshka/shared/messages/client-to-bff/error-message");
14
13
  const browser_get_geolocation_success_message_1 = require("@matreshka/shared/messages/client-to-bff/platforms/browser/browser-get-geolocation-success-message");
15
14
  const browser_request_push_notifications_action_granted_message_1 = require("@matreshka/shared/messages/client-to-bff/platforms/browser/browser-request-push-notifications-action-granted-message");
16
15
  const platform_webauthn_create_credential_success_message_1 = require("@matreshka/shared/messages/client-to-bff/platforms/platform-webauthn-create-credential-success-message");
17
16
  const platform_webauthn_get_credential_success_message_1 = require("@matreshka/shared/messages/client-to-bff/platforms/platform-webauthn-get-credential-success-message");
18
- const targeted_message_1 = require("@matreshka/shared/messages/targeted-message");
19
- const rxjs_1 = require("rxjs");
20
17
  const v4_1 = require("zod/v4");
21
- const incoming_message_observer_1 = require("../core/utils/incoming-message-observer");
18
+ const targeted_client_platform_action_1 = require("./utils/targeted-client-platform-action");
22
19
  const web_platform_1 = require("./web-platform");
23
20
  const pushSubscriptionGrantedMessageSchema = v4_1.z.strictObject({
24
21
  subscription: v4_1.z.strictObject({
@@ -30,9 +27,6 @@ const pushSubscriptionGrantedMessageSchema = v4_1.z.strictObject({
30
27
  }),
31
28
  }),
32
29
  });
33
- const errorMessagePayloadSchema = v4_1.z.strictObject({
34
- message: v4_1.z.string(),
35
- });
36
30
  /**
37
31
  * Платформа для браузерной версии клиента.
38
32
  *
@@ -42,32 +36,21 @@ class BrowserPlatform extends web_platform_1.WebPlatform {
42
36
  /**
43
37
  * Запрашивает геолокацию пользователя в веб-клиенте.
44
38
  *
45
- * @param config Объект с обработчиками успешного получения геолокации и отмены.
46
39
  */
47
- getGeolocation(config) {
48
- const scope = "platform-action-" + crypto.randomUUID();
49
- const subscription = this.client.incomingMessage$
50
- .pipe((0, rxjs_1.filter)((unsafeMessage) => (0, targeted_message_1.isTargetedMessage)(unsafeMessage) && unsafeMessage.target === scope))
51
- .subscribe((0, incoming_message_observer_1.incomingMessageObserver)(this.client, (unsafeMessage) => {
52
- subscription.unsubscribe();
53
- if (unsafeMessage instanceof browser_get_geolocation_success_message_1.BrowserGetGeolocationSuccessMessage) {
54
- const messagePayload = v4_1.z
55
- .strictObject({
56
- latitude: v4_1.z.number(),
57
- longitude: v4_1.z.number(),
58
- })
59
- .parse(unsafeMessage.payload);
60
- config.onSuccess(messagePayload);
61
- return;
62
- }
63
- if (unsafeMessage instanceof error_message_1.ErrorMessage) {
64
- const messagePayload = errorMessagePayloadSchema.parse(unsafeMessage.payload);
65
- if (typeof config.onError === "function") {
66
- config.onError(messagePayload.message);
40
+ getGeolocation() {
41
+ return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
42
+ outgoingMessage: (scope) => new browser_get_geolocation_message_1.BrowserGetGeolocationMessage(scope),
43
+ parseSuccess: (unsafeMessage) => {
44
+ if (unsafeMessage instanceof browser_get_geolocation_success_message_1.BrowserGetGeolocationSuccessMessage) {
45
+ return v4_1.z
46
+ .strictObject({
47
+ latitude: v4_1.z.number(),
48
+ longitude: v4_1.z.number(),
49
+ })
50
+ .parse(unsafeMessage.payload);
67
51
  }
68
- }
69
- }));
70
- this.client.outcomingMessage$.next(new browser_get_geolocation_message_1.BrowserGetGeolocationMessage(scope));
52
+ },
53
+ });
71
54
  }
72
55
  /**
73
56
  * Добавляет событие в календарь клиента.
@@ -75,7 +58,9 @@ class BrowserPlatform extends web_platform_1.WebPlatform {
75
58
  * @param data Данные события: начало, конец, описание, место проведения и заголовок.
76
59
  */
77
60
  addEventToCalendar(data) {
78
- this.client.outcomingMessage$.next(new browser_add_event_to_calendar_message_1.BrowserAddEventToCalendarMessage(data));
61
+ return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
62
+ outgoingMessage: (scope) => new browser_add_event_to_calendar_message_1.BrowserAddEventToCalendarMessage(scope, data),
63
+ });
79
64
  }
80
65
  /**
81
66
  * Сохраняет CSV-файл на устройстве пользователя.
@@ -84,10 +69,12 @@ class BrowserPlatform extends web_platform_1.WebPlatform {
84
69
  * @param content Двумерный массив строк, представляющий содержимое CSV.
85
70
  */
86
71
  downloadCsvContent(filename, content) {
87
- this.client.outcomingMessage$.next(new browser_download_csv_content_message_1.BrowserDownloadCsvContentMessage({
88
- filename: filename.endsWith(".csv") ? filename : filename + ".csv",
89
- content,
90
- }));
72
+ return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
73
+ outgoingMessage: (scope) => new browser_download_csv_content_message_1.BrowserDownloadCsvContentMessage(scope, {
74
+ filename: filename.endsWith(".csv") ? filename : filename + ".csv",
75
+ content,
76
+ }),
77
+ });
91
78
  }
92
79
  /**
93
80
  * Инициирует загрузку файла по указанному URL.
@@ -98,7 +85,9 @@ class BrowserPlatform extends web_platform_1.WebPlatform {
98
85
  downloadFile(url, filename) {
99
86
  // https://developer.mozilla.org/ru/docs/Web/HTML/Element/a#Attributes
100
87
  // Принудительная загрузка файлов, которые браузер может открыть, а не скачать (изображения и pdf), будет только для того же домена, иначе будет срабатывать открытие, либо будет игнорировать приоритетный filename
101
- this.client.outcomingMessage$.next(new browser_download_file_message_1.BrowserDownloadFileMessage({ url, filename }));
88
+ return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
89
+ outgoingMessage: (scope) => new browser_download_file_message_1.BrowserDownloadFileMessage(scope, { url, filename }),
90
+ });
102
91
  }
103
92
  /**
104
93
  * Открывает файл во встроенном просмотрщике браузера (PDF, изображения и т.д.).
@@ -106,7 +95,9 @@ class BrowserPlatform extends web_platform_1.WebPlatform {
106
95
  * @param url Ссылка на файл (blob: или HTTP).
107
96
  */
108
97
  openFile(url) {
109
- this.client.outcomingMessage$.next(new browser_open_file_message_1.BrowserOpenFileMessage({ url }));
98
+ return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
99
+ outgoingMessage: (scope) => new browser_open_file_message_1.BrowserOpenFileMessage(scope, { url }),
100
+ });
110
101
  }
111
102
  /**
112
103
  * Делится содержимым через системное диалоговое окно обмена.
@@ -114,35 +105,25 @@ class BrowserPlatform extends web_platform_1.WebPlatform {
114
105
  * @param data Объект с текстом, ссылкой и/или заголовком.
115
106
  */
116
107
  share(data) {
117
- this.client.outcomingMessage$.next(new browser_share_message_1.BrowserShareMessage(data));
108
+ return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
109
+ outgoingMessage: (scope) => new browser_share_message_1.BrowserShareMessage(scope, data),
110
+ });
118
111
  }
119
112
  /**
120
113
  * Запрашивает разрешение на push-уведомления и обрабатывает результат.
121
114
  *
122
- * @param config Объект с колбэками: `onGranted` при успехе, `onError` при ошибке.
115
+ * @param publicKey Публичный VAPID-ключ для подписки в браузере.
123
116
  */
124
- registerPushNotifications(config) {
125
- const scope = "platform-action-" + crypto.randomUUID();
126
- const subscription = this.client.incomingMessage$
127
- .pipe((0, rxjs_1.filter)((unsafeMessage) => (0, targeted_message_1.isTargetedMessage)(unsafeMessage) && unsafeMessage.target === scope))
128
- .subscribe((0, incoming_message_observer_1.incomingMessageObserver)(this.client, (unsafeMessage) => {
129
- subscription.unsubscribe();
130
- if (unsafeMessage instanceof
131
- browser_request_push_notifications_action_granted_message_1.BrowserRequestPushNotificationsActionGrantedMessage) {
132
- const messagePayload = pushSubscriptionGrantedMessageSchema.parse(unsafeMessage.payload);
133
- config.onGranted(messagePayload.subscription);
134
- return;
135
- }
136
- if (unsafeMessage instanceof error_message_1.ErrorMessage) {
137
- const messagePayload = errorMessagePayloadSchema.parse(unsafeMessage.payload);
138
- if ("onError" in config) {
139
- config.onError(messagePayload.message);
117
+ registerPushNotifications(publicKey) {
118
+ return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
119
+ outgoingMessage: (scope) => new browser_request_push_notifications_message_1.BrowserRequestPushNotificationsMessage(scope, { publicKey }),
120
+ parseSuccess: (unsafeMessage) => {
121
+ if (unsafeMessage instanceof
122
+ browser_request_push_notifications_action_granted_message_1.BrowserRequestPushNotificationsActionGrantedMessage) {
123
+ return pushSubscriptionGrantedMessageSchema.parse(unsafeMessage.payload).subscription;
140
124
  }
141
- }
142
- }));
143
- this.client.outcomingMessage$.next(new browser_request_push_notifications_message_1.BrowserRequestPushNotificationsMessage(scope, {
144
- publicKey: config.publicKey,
145
- }));
125
+ },
126
+ });
146
127
  }
147
128
  /**
148
129
  * Регистрация WebAuthn credential (passkey / security key) в браузерном клиенте.
@@ -150,55 +131,31 @@ class BrowserPlatform extends web_platform_1.WebPlatform {
150
131
  * @remarks Только `BrowserPlatform` / `PwaPlatform`. Mobile — не поддерживается.
151
132
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API
152
133
  */
153
- createWebAuthnCredential(config) {
154
- this.runWebAuthnPlatformAction({
155
- target: "platform-action-" + crypto.randomUUID(),
156
- successMessageType: platform_webauthn_create_credential_success_message_1.PlatformWebAuthnCreateCredentialSuccessMessage,
157
- outgoingMessage: (target) => new platform_webauthn_create_credential_message_1.PlatformWebAuthnCreateCredentialMessage(target, {
158
- optionsJSON: config.optionsJSON,
159
- }),
160
- parseSuccessPayload: (payload) => webAuthnRegistrationResponseSchema.parse(payload),
161
- onSuccess: (payload) => config.onSuccess(payload.credentialJSON),
162
- onError: config.onError,
134
+ createWebAuthnCredential(optionsJSON) {
135
+ return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
136
+ outgoingMessage: (scope) => new platform_webauthn_create_credential_message_1.PlatformWebAuthnCreateCredentialMessage(scope, { optionsJSON }),
137
+ parseSuccess: (unsafeMessage) => {
138
+ if (unsafeMessage instanceof
139
+ platform_webauthn_create_credential_success_message_1.PlatformWebAuthnCreateCredentialSuccessMessage) {
140
+ const payload = webAuthnRegistrationResponseSchema.parse(unsafeMessage.payload);
141
+ return payload.credentialJSON;
142
+ }
143
+ },
163
144
  });
164
145
  }
165
146
  /**
166
147
  * Аутентификация через WebAuthn credential в браузерном клиенте.
167
148
  */
168
- getWebAuthnCredential(config) {
169
- this.runWebAuthnPlatformAction({
170
- target: "platform-action-" + crypto.randomUUID(),
171
- successMessageType: platform_webauthn_get_credential_success_message_1.PlatformWebAuthnGetCredentialSuccessMessage,
172
- outgoingMessage: (target) => new platform_webauthn_get_credential_message_1.PlatformWebAuthnGetCredentialMessage(target, {
173
- optionsJSON: config.optionsJSON,
174
- }),
175
- parseSuccessPayload: (payload) => webAuthnAuthenticationResponseSchema.parse(payload),
176
- onSuccess: (payload) => config.onSuccess(payload.credentialJSON),
177
- onError: config.onError,
178
- });
179
- }
180
- runWebAuthnPlatformAction(config) {
181
- const errorPayloadSchema = v4_1.z.strictObject({
182
- message: v4_1.z.string(),
183
- });
184
- const subscription = this.client.incomingMessage$
185
- .pipe((0, rxjs_1.filter)((unsafeMessage) => (0, targeted_message_1.isTargetedMessage)(unsafeMessage) &&
186
- unsafeMessage.target === config.target))
187
- .subscribe((0, incoming_message_observer_1.incomingMessageObserver)(this.client, (unsafeMessage) => {
188
- subscription.unsubscribe();
189
- if (unsafeMessage instanceof config.successMessageType) {
190
- const payload = config.parseSuccessPayload(unsafeMessage.payload);
191
- config.onSuccess(payload);
192
- return;
193
- }
194
- if (unsafeMessage instanceof error_message_1.ErrorMessage) {
195
- const payload = errorPayloadSchema.parse(unsafeMessage.payload);
196
- if (typeof config.onError === "function") {
197
- config.onError(payload.message);
149
+ getWebAuthnCredential(optionsJSON) {
150
+ return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
151
+ outgoingMessage: (scope) => new platform_webauthn_get_credential_message_1.PlatformWebAuthnGetCredentialMessage(scope, { optionsJSON }),
152
+ parseSuccess: (unsafeMessage) => {
153
+ if (unsafeMessage instanceof platform_webauthn_get_credential_success_message_1.PlatformWebAuthnGetCredentialSuccessMessage) {
154
+ const payload = webAuthnAuthenticationResponseSchema.parse(unsafeMessage.payload);
155
+ return payload.credentialJSON;
198
156
  }
199
- }
200
- }));
201
- this.client.outcomingMessage$.next(config.outgoingMessage(config.target));
157
+ },
158
+ });
202
159
  }
203
160
  }
204
161
  exports.BrowserPlatform = BrowserPlatform;
@@ -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
  /**
@@ -31,14 +32,7 @@ type MaxWebAppInitData = {
31
32
  * Платформа для Max Mini App.
32
33
  */
33
34
  export declare class MaxMiniAppPlatform extends WebPlatform {
34
- /**
35
- * Запрашивает контактные данные пользователя в Max Mini App.
36
- *
37
- * @param config Объект с обработчиками успешного получения контакта и отмены.
38
- */
39
- requestContact(config: {
40
- onReceive: (data: z.infer<typeof requestContactSuccessMessageSchema>) => void;
41
- }): void;
35
+ requestContact(): Observable<z.infer<typeof requestContactSuccessMessageSchema>>;
42
36
  initData(botToken: string): MaxWebAppInitData;
43
37
  private verifyMaxWebAppData;
44
38
  }
@@ -6,11 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.MaxMiniAppPlatform = void 0;
7
7
  const max_mini_app_request_contact_message_1 = require("@matreshka/shared/messages/bff-to-client/platforms/max-mini-app/max-mini-app-request-contact-message");
8
8
  const max_mini_app_request_contact_action_success_message_1 = require("@matreshka/shared/messages/client-to-bff/platforms/max-mini-app/max-mini-app-request-contact-action-success-message");
9
- const targeted_message_1 = require("@matreshka/shared/messages/targeted-message");
10
9
  const crypto_1 = __importDefault(require("crypto"));
11
- const rxjs_1 = require("rxjs");
12
10
  const v4_1 = require("zod/v4");
13
- const incoming_message_observer_1 = require("../core/utils/incoming-message-observer");
11
+ const targeted_client_platform_action_1 = require("./utils/targeted-client-platform-action");
14
12
  const web_platform_1 = require("./web-platform");
15
13
  /**
16
14
  * Входящее сообщение с данными пользователя после успешного запроса контакта.
@@ -22,24 +20,15 @@ const requestContactSuccessMessageSchema = v4_1.z.strictObject({
22
20
  * Платформа для Max Mini App.
23
21
  */
24
22
  class MaxMiniAppPlatform extends web_platform_1.WebPlatform {
25
- /**
26
- * Запрашивает контактные данные пользователя в Max Mini App.
27
- *
28
- * @param config Объект с обработчиками успешного получения контакта и отмены.
29
- */
30
- requestContact(config) {
31
- const scope = "platform-action-" + crypto_1.default.randomUUID();
32
- const subscription = this.client.incomingMessage$
33
- .pipe((0, rxjs_1.filter)((unsafeMessage) => (0, targeted_message_1.isTargetedMessage)(unsafeMessage) && unsafeMessage.target === scope))
34
- .subscribe((0, incoming_message_observer_1.incomingMessageObserver)(this.client, (unsafeMessage) => {
35
- subscription.unsubscribe();
36
- if (unsafeMessage instanceof
37
- max_mini_app_request_contact_action_success_message_1.MaxMiniAppRequestContactActionSuccessMessage) {
38
- const messagePayload = requestContactSuccessMessageSchema.parse(unsafeMessage.payload);
39
- config.onReceive(messagePayload);
40
- }
41
- }));
42
- this.client.outcomingMessage$.next(new max_mini_app_request_contact_message_1.MaxMiniAppRequestContactMessage(scope));
23
+ requestContact() {
24
+ return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
25
+ outgoingMessage: (scope) => new max_mini_app_request_contact_message_1.MaxMiniAppRequestContactMessage(scope),
26
+ parseSuccess: (unsafeMessage) => {
27
+ if (unsafeMessage instanceof max_mini_app_request_contact_action_success_message_1.MaxMiniAppRequestContactActionSuccessMessage) {
28
+ return requestContactSuccessMessageSchema.parse(unsafeMessage.payload);
29
+ }
30
+ },
31
+ });
43
32
  }
44
33
  initData(botToken) {
45
34
  const initDataString = this.client.state$.getValue().platform