@matreshka/bff 0.17.0 → 0.20.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 (53) hide show
  1. package/dist/components/board.d.ts +4 -7
  2. package/dist/components/board.js +7 -51
  3. package/dist/components/camera.d.ts +1 -4
  4. package/dist/components/camera.js +6 -26
  5. package/dist/components/component.d.ts +26 -5
  6. package/dist/components/component.js +35 -2
  7. package/dist/components/container.js +8 -11
  8. package/dist/components/dialog.d.ts +1 -4
  9. package/dist/components/dialog.js +5 -21
  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/inputs/text-editor.d.ts +14 -14
  14. package/dist/components/inputs/text-editor.js +14 -154
  15. package/dist/components/map.d.ts +4 -7
  16. package/dist/components/map.js +6 -52
  17. package/dist/components/page.d.ts +0 -1
  18. package/dist/components/page.js +4 -10
  19. package/dist/components/popover.d.ts +1 -4
  20. package/dist/components/popover.js +5 -21
  21. package/dist/components/stack.d.ts +2 -5
  22. package/dist/components/stack.js +6 -28
  23. package/dist/components/utils/targeted-client-component-action.d.ts +5 -0
  24. package/dist/components/utils/targeted-client-component-action.js +25 -0
  25. package/dist/core/utils/serialize-component-tree.d.ts +3 -0
  26. package/dist/core/utils/serialize-component-tree.js +21 -0
  27. package/dist/core/utils/targeted-client-action.d.ts +19 -0
  28. package/dist/core/utils/targeted-client-action.js +68 -0
  29. package/dist/platforms/browser-platform.d.ts +21 -37
  30. package/dist/platforms/browser-platform.js +61 -104
  31. package/dist/platforms/max-mini-app-platform.d.ts +2 -8
  32. package/dist/platforms/max-mini-app-platform.js +10 -21
  33. package/dist/platforms/mobile-platform.d.ts +32 -58
  34. package/dist/platforms/mobile-platform.js +139 -211
  35. package/dist/platforms/platform.d.ts +32 -49
  36. package/dist/platforms/platform.js +77 -87
  37. package/dist/platforms/telegram-mini-app-platform.d.ts +16 -34
  38. package/dist/platforms/telegram-mini-app-platform.js +41 -92
  39. package/dist/platforms/utils/client-back-platform-action.d.ts +9 -0
  40. package/dist/platforms/utils/client-back-platform-action.js +48 -0
  41. package/dist/platforms/utils/client-navigate-platform-action.d.ts +19 -0
  42. package/dist/platforms/utils/client-navigate-platform-action.js +60 -0
  43. package/dist/platforms/utils/client-reload-platform-action.d.ts +8 -0
  44. package/dist/platforms/utils/client-reload-platform-action.js +41 -0
  45. package/dist/platforms/utils/client-route-page-wait.d.ts +11 -0
  46. package/dist/platforms/utils/client-route-page-wait.js +33 -0
  47. package/dist/platforms/utils/match-navigate-path.d.ts +11 -0
  48. package/dist/platforms/utils/match-navigate-path.js +95 -0
  49. package/dist/platforms/utils/targeted-client-platform-action.d.ts +11 -0
  50. package/dist/platforms/utils/targeted-client-platform-action.js +25 -0
  51. package/dist/platforms/utils/targeted-client-platform-stream.d.ts +17 -0
  52. package/dist/platforms/utils/targeted-client-platform-stream.js +90 -0
  53. 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,
@@ -105,32 +104,14 @@ class Stack extends component_1.Component {
105
104
  * - иное отрицательное `value` — отступ от конца (например `-16`).
106
105
  */
107
106
  scrollTo(value, smooth = false, instances) {
108
- if (instances) {
109
- instances
110
- .filter((instance) => instance.client)
111
- .forEach((instance) => {
112
- instance.client.outcomingMessage$.next(new component_scroll_to_message_1.ComponentScrollToMessage(instance.id, {
113
- value,
114
- smooth,
115
- }));
116
- });
117
- }
118
- else {
119
- this.broadcast(new component_scroll_to_message_1.ComponentScrollToMessage(this.id, {
120
- value,
121
- smooth,
122
- }));
123
- }
124
- return this;
107
+ const payload = { value, smooth };
108
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new component_scroll_to_message_1.ComponentScrollToMessage(target, { ...payload, actionScope }));
125
109
  }
126
110
  serializeRuleOverrides(overrides) {
127
- const out = { ...overrides };
111
+ const out = super.serializeRuleOverrides(overrides);
128
112
  if (overrides.content !== undefined) {
129
113
  out.content = (0, core_1.serializeComponentList)(overrides.content);
130
114
  }
131
- if (overrides.overlays !== undefined) {
132
- out.overlays = (0, core_1.serializeOverlays)(overrides.overlays);
133
- }
134
115
  if (overrides.flexItem !== undefined) {
135
116
  out.flexItem = (0, flex_item_1.normalizeFlexItem)(overrides.flexItem);
136
117
  }
@@ -138,15 +119,12 @@ class Stack extends component_1.Component {
138
119
  }
139
120
  serialize(instance) {
140
121
  const result = super.serialize(instance);
141
- const p = this.properties;
142
122
  return {
143
123
  ...result,
144
124
  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
- },
125
+ properties: this.buildPropertiesForClient({
126
+ content: (0, core_1.serializeComponentList)(this.properties.content),
127
+ }),
150
128
  };
151
129
  }
152
130
  }
@@ -0,0 +1,5 @@
1
+ import { ComponentCommandMessage } from "@matreshka/shared/messages/bff-to-client/component-command-message";
2
+ import { Observable } from "rxjs";
3
+ import { Client } from "../../core";
4
+ export declare const COMPONENT_ACTION_SCOPE_PREFIX = "component-action-";
5
+ export declare function targetedClientComponentAction(client: Client, outgoingMessage: (actionScope: string) => ComponentCommandMessage): Observable<void>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.COMPONENT_ACTION_SCOPE_PREFIX = void 0;
4
+ exports.targetedClientComponentAction = targetedClientComponentAction;
5
+ const rxjs_1 = require("rxjs");
6
+ const targeted_client_action_1 = require("../../core/utils/targeted-client-action");
7
+ exports.COMPONENT_ACTION_SCOPE_PREFIX = "component-action-";
8
+ function targetedClientComponentAction(client, outgoingMessage) {
9
+ const result$ = new rxjs_1.ReplaySubject(1);
10
+ (0, targeted_client_action_1.startTargetedClientAction)(client, {
11
+ scopePrefix: exports.COMPONENT_ACTION_SCOPE_PREFIX,
12
+ start: (scope) => {
13
+ client.outcomingMessage$.next(outgoingMessage(scope));
14
+ },
15
+ }, {
16
+ next: () => {
17
+ result$.next(undefined);
18
+ result$.complete();
19
+ },
20
+ error: (error) => result$.error(error),
21
+ complete: () => result$.complete(),
22
+ closed: () => result$.closed,
23
+ });
24
+ return result$.asObservable();
25
+ }
@@ -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);
@@ -0,0 +1,19 @@
1
+ import { AnyClientToBffMessage } from "@matreshka/shared/messages/client-to-bff/client-to-bff-message";
2
+ import { Client } from "../client";
3
+ export type TargetedClientActionTerminal<T> = {
4
+ next: (value: T) => void;
5
+ error: (error: Error) => void;
6
+ complete: () => void;
7
+ closed: () => boolean;
8
+ };
9
+ export type TargetedClientActionConfig<T> = {
10
+ scopePrefix: string;
11
+ start: (scope: string, client: Client) => void;
12
+ parseSuccess?: (unsafeMessage: AnyClientToBffMessage) => T | undefined;
13
+ parseFailure?: (unsafeMessage: AnyClientToBffMessage) => Error | undefined;
14
+ };
15
+ export declare function createTargetedActionScope(prefix: string): string;
16
+ export declare function startTargetedClientAction<T>(client: Client, config: TargetedClientActionConfig<T>, terminal: TargetedClientActionTerminal<T>): {
17
+ scope: string;
18
+ teardown: () => void;
19
+ };
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTargetedActionScope = createTargetedActionScope;
4
+ exports.startTargetedClientAction = startTargetedClientAction;
5
+ const action_completed_message_1 = require("@matreshka/shared/messages/client-to-bff/action-completed-message");
6
+ const error_message_1 = require("@matreshka/shared/messages/client-to-bff/error-message");
7
+ const targeted_message_1 = require("@matreshka/shared/messages/targeted-message");
8
+ const rxjs_1 = require("rxjs");
9
+ const v4_1 = require("zod/v4");
10
+ const incoming_message_observer_1 = require("./incoming-message-observer");
11
+ const errorMessagePayloadSchema = v4_1.z.strictObject({
12
+ message: v4_1.z.string(),
13
+ });
14
+ function createTargetedActionScope(prefix) {
15
+ return prefix + crypto.randomUUID();
16
+ }
17
+ function startTargetedClientAction(client, config, terminal) {
18
+ const scope = createTargetedActionScope(config.scopePrefix);
19
+ let finalized = false;
20
+ const teardown = () => {
21
+ if (finalized) {
22
+ return;
23
+ }
24
+ finalized = true;
25
+ subscription.unsubscribe();
26
+ destroySubscription.unsubscribe();
27
+ };
28
+ const finish = (notify) => {
29
+ notify();
30
+ teardown();
31
+ };
32
+ const subscription = client.incomingMessage$
33
+ .pipe((0, rxjs_1.filter)((unsafeMessage) => (0, targeted_message_1.isTargetedMessage)(unsafeMessage) && unsafeMessage.target === scope), (0, rxjs_1.take)(1))
34
+ .subscribe((0, incoming_message_observer_1.incomingMessageObserver)(client, (unsafeMessage) => {
35
+ if (unsafeMessage instanceof error_message_1.ErrorMessage) {
36
+ const messagePayload = errorMessagePayloadSchema.parse(unsafeMessage.payload);
37
+ finish(() => terminal.error(new Error(messagePayload.message)));
38
+ return;
39
+ }
40
+ if (unsafeMessage instanceof action_completed_message_1.ActionCompletedMessage) {
41
+ finish(() => {
42
+ terminal.next(undefined);
43
+ terminal.complete();
44
+ });
45
+ return;
46
+ }
47
+ const failure = config.parseFailure?.(unsafeMessage);
48
+ if (failure) {
49
+ finish(() => terminal.error(failure));
50
+ return;
51
+ }
52
+ const value = config.parseSuccess?.(unsafeMessage);
53
+ if (value !== undefined) {
54
+ finish(() => {
55
+ terminal.next(value);
56
+ terminal.complete();
57
+ });
58
+ }
59
+ }));
60
+ const destroySubscription = client.destroy$.subscribe(() => {
61
+ if (!terminal.closed()) {
62
+ terminal.complete();
63
+ }
64
+ teardown();
65
+ });
66
+ config.start(scope, client);
67
+ return { scope, teardown };
68
+ }
@@ -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
  }