@suro4ek/appmetrica-push-sdk 1.0.2

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.
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Конфигурация для инициализации AppMetrica Push SDK
3
+ */
4
+ export interface PushConfig {
5
+ /** Режим отладки */
6
+ debugMode?: boolean;
7
+ /** APNs device token для iOS (опционально) */
8
+ apnsToken?: string;
9
+ /** App Group для расширений (опционально) */
10
+ appGroup?: string;
11
+ }
12
+
13
+ /**
14
+ * Информация о SDK
15
+ */
16
+ export interface SDKInfo {
17
+ /** Версия AppMetrica Push SDK */
18
+ version: string;
19
+ /** Платформа */
20
+ platform: string;
21
+ /** Название SDK */
22
+ sdkName?: string;
23
+ /** Версия нашей библиотеки */
24
+ libraryVersion?: string;
25
+ }
26
+
27
+ /**
28
+ * Результат инициализации
29
+ */
30
+ export interface InitializationResult {
31
+ /** Успешность инициализации */
32
+ success: boolean;
33
+ /** Сообщение об ошибке */
34
+ error?: string;
35
+ }
@@ -0,0 +1,121 @@
1
+ import AppMetricaPush from "../AppMetricaPushModule";
2
+ import { PushConfig } from "../types";
3
+
4
+ /**
5
+ * Инициализация AppMetrica Push SDK с проверками
6
+ */
7
+ export const initializeAppMetricaPush = async (
8
+ config: PushConfig,
9
+ forceReinit = false
10
+ ): Promise<boolean> => {
11
+ const instance = AppMetricaPush.getInstance();
12
+
13
+ if (instance.isSDKInitialized() && !forceReinit) {
14
+ console.warn("AppMetrica Push SDK is already initialized");
15
+ return true;
16
+ }
17
+
18
+ const result = await instance.initialize(config);
19
+ return result.success;
20
+ };
21
+
22
+ /**
23
+ * Проверка, что уведомление от AppMetrica
24
+ * Используется в собственных сервисах обработки push уведомлений
25
+ */
26
+ export const isNotificationFromAppMetrica = async (
27
+ notification: any
28
+ ): Promise<boolean> => {
29
+ const instance = AppMetricaPush.getInstance();
30
+
31
+ if (!instance.isSDKInitialized()) {
32
+ console.error("AppMetrica Push SDK is not initialized");
33
+ return false;
34
+ }
35
+
36
+ try {
37
+ return await instance.isNotificationFromAppMetrica(notification);
38
+ } catch (error) {
39
+ console.error("Failed to check if notification is from AppMetrica:", error);
40
+ return false;
41
+ }
42
+ };
43
+
44
+ /**
45
+ * Получение информации о SDK
46
+ */
47
+ export const getPushSDKInfo = async () => {
48
+ const instance = AppMetricaPush.getInstance();
49
+
50
+ try {
51
+ return await instance.getSDKInfo();
52
+ } catch (error) {
53
+ console.error("Failed to get SDK info:", error);
54
+ return null;
55
+ }
56
+ };
57
+
58
+ /**
59
+ * Получение дополнительной информации из push-уведомления
60
+ * Согласно документации AppMetrica Push SDK
61
+ */
62
+ export const getUserDataFromNotification = async (notification: any) => {
63
+ const instance = AppMetricaPush.getInstance();
64
+
65
+ if (!instance.isSDKInitialized()) {
66
+ console.error("AppMetrica Push SDK is not initialized");
67
+ return null;
68
+ }
69
+
70
+ try {
71
+ return await instance.getUserData(notification);
72
+ } catch (error) {
73
+ console.error("Failed to get user data from notification:", error);
74
+ return null;
75
+ }
76
+ };
77
+
78
+ /**
79
+ * Проверка инициализации SDK
80
+ */
81
+ export const isSDKInitialized = (): boolean => {
82
+ const instance = AppMetricaPush.getInstance();
83
+ return instance.isSDKInitialized();
84
+ };
85
+
86
+ /**
87
+ * Получение текущей конфигурации
88
+ */
89
+ export const getCurrentConfig = () => {
90
+ const instance = AppMetricaPush.getInstance();
91
+ return instance.getConfig();
92
+ };
93
+
94
+ /**
95
+ * Регистрация device token для push-уведомлений
96
+ */
97
+ export const registerDeviceToken = async (
98
+ deviceToken: string
99
+ ): Promise<boolean> => {
100
+ const instance = AppMetricaPush.getInstance();
101
+
102
+ if (!instance.isSDKInitialized()) {
103
+ console.error("AppMetrica Push SDK is not initialized");
104
+ return false;
105
+ }
106
+
107
+ try {
108
+ return await instance.registerDeviceToken(deviceToken);
109
+ } catch (error) {
110
+ console.error("Failed to register device token:", error);
111
+ return false;
112
+ }
113
+ };
114
+
115
+ /**
116
+ * Сброс состояния SDK (для тестирования)
117
+ */
118
+ export const resetSDK = (): void => {
119
+ const instance = AppMetricaPush.getInstance();
120
+ instance.reset();
121
+ };