@dashx/react-native 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/README.md +1 -1
  2. package/ios/DashXReactNative.mm +7 -7
  3. package/ios/DashXReactNative.swift +15 -11
  4. package/package.json +13 -11
  5. package/.claude/settings.local.json +0 -7
  6. package/.claude/worktrees/autocapture-conventions-review-78f665/.gitattributes +0 -1
  7. package/.claude/worktrees/autocapture-conventions-review-78f665/.github/workflows/ci.yml +0 -67
  8. package/.claude/worktrees/autocapture-conventions-review-78f665/.gitignore +0 -49
  9. package/.claude/worktrees/autocapture-conventions-review-78f665/.nvmrc +0 -1
  10. package/.claude/worktrees/autocapture-conventions-review-78f665/CHANGELOG.md +0 -144
  11. package/.claude/worktrees/autocapture-conventions-review-78f665/CONTRIBUTING.md +0 -190
  12. package/.claude/worktrees/autocapture-conventions-review-78f665/DashXReactNative.podspec +0 -38
  13. package/.claude/worktrees/autocapture-conventions-review-78f665/LICENSE +0 -21
  14. package/.claude/worktrees/autocapture-conventions-review-78f665/README.md +0 -97
  15. package/.claude/worktrees/autocapture-conventions-review-78f665/__tests__/fallback.test.js +0 -72
  16. package/.claude/worktrees/autocapture-conventions-review-78f665/__tests__/index.test.js +0 -702
  17. package/.claude/worktrees/autocapture-conventions-review-78f665/android/.gitignore +0 -10
  18. package/.claude/worktrees/autocapture-conventions-review-78f665/android/.gradle/8.14.3/checksums/checksums.lock +0 -0
  19. package/.claude/worktrees/autocapture-conventions-review-78f665/android/.gradle/8.14.3/fileChanges/last-build.bin +0 -0
  20. package/.claude/worktrees/autocapture-conventions-review-78f665/android/.gradle/8.14.3/fileHashes/fileHashes.lock +0 -0
  21. package/.claude/worktrees/autocapture-conventions-review-78f665/android/.gradle/8.14.3/gc.properties +0 -0
  22. package/.claude/worktrees/autocapture-conventions-review-78f665/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  23. package/.claude/worktrees/autocapture-conventions-review-78f665/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  24. package/.claude/worktrees/autocapture-conventions-review-78f665/android/.gradle/vcs-1/gc.properties +0 -0
  25. package/.claude/worktrees/autocapture-conventions-review-78f665/android/build/reports/problems/problems-report.html +0 -663
  26. package/.claude/worktrees/autocapture-conventions-review-78f665/android/build.gradle +0 -121
  27. package/.claude/worktrees/autocapture-conventions-review-78f665/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  28. package/.claude/worktrees/autocapture-conventions-review-78f665/android/gradle/wrapper/gradle-wrapper.properties +0 -6
  29. package/.claude/worktrees/autocapture-conventions-review-78f665/android/gradle.properties +0 -1
  30. package/.claude/worktrees/autocapture-conventions-review-78f665/android/gradlew +0 -185
  31. package/.claude/worktrees/autocapture-conventions-review-78f665/android/gradlew.bat +0 -89
  32. package/.claude/worktrees/autocapture-conventions-review-78f665/android/settings.gradle +0 -27
  33. package/.claude/worktrees/autocapture-conventions-review-78f665/android/src/main/AndroidManifest.xml +0 -19
  34. package/.claude/worktrees/autocapture-conventions-review-78f665/android/src/main/java/com/dashx/rn/sdk/DashXNotificationClickedListener.kt +0 -113
  35. package/.claude/worktrees/autocapture-conventions-review-78f665/android/src/main/java/com/dashx/rn/sdk/DashXReactNativeFirebaseMessagingService.kt +0 -72
  36. package/.claude/worktrees/autocapture-conventions-review-78f665/android/src/main/java/com/dashx/rn/sdk/DashXReactNativeModuleImpl.kt +0 -445
  37. package/.claude/worktrees/autocapture-conventions-review-78f665/android/src/main/java/com/dashx/rn/sdk/MessageReceivedEventHolder.kt +0 -14
  38. package/.claude/worktrees/autocapture-conventions-review-78f665/android/src/main/java/com/dashx/rn/sdk/ReactNativeLibraryInfoProvider.kt +0 -8
  39. package/.claude/worktrees/autocapture-conventions-review-78f665/android/src/main/java/com/dashx/rn/sdk/util/Utils.kt +0 -208
  40. package/.claude/worktrees/autocapture-conventions-review-78f665/android/src/main/resources/META-INF/services/com.dashx.android.DashXLibraryInfoProvider +0 -1
  41. package/.claude/worktrees/autocapture-conventions-review-78f665/android/src/newarch/java/com/dashx/rn/sdk/DashXReactNativeModule.kt +0 -85
  42. package/.claude/worktrees/autocapture-conventions-review-78f665/android/src/newarch/java/com/dashx/rn/sdk/DashXReactNativePackage.kt +0 -33
  43. package/.claude/worktrees/autocapture-conventions-review-78f665/android/src/oldarch/java/com/dashx/rn/sdk/DashXReactNativeModule.kt +0 -106
  44. package/.claude/worktrees/autocapture-conventions-review-78f665/android/src/oldarch/java/com/dashx/rn/sdk/DashXReactNativePackage.kt +0 -33
  45. package/.claude/worktrees/autocapture-conventions-review-78f665/android/src/test/java/com/dashx/rn/sdk/util/UtilsTest.kt +0 -305
  46. package/.claude/worktrees/autocapture-conventions-review-78f665/babel.config.js +0 -3
  47. package/.claude/worktrees/autocapture-conventions-review-78f665/index.d.ts +0 -321
  48. package/.claude/worktrees/autocapture-conventions-review-78f665/index.js +0 -300
  49. package/.claude/worktrees/autocapture-conventions-review-78f665/ios/DashXEventEmitter.swift +0 -15
  50. package/.claude/worktrees/autocapture-conventions-review-78f665/ios/DashXNotificationHandler.swift +0 -301
  51. package/.claude/worktrees/autocapture-conventions-review-78f665/ios/DashXReactNative-Bridging-Header.h +0 -3
  52. package/.claude/worktrees/autocapture-conventions-review-78f665/ios/DashXReactNative.mm +0 -77
  53. package/.claude/worktrees/autocapture-conventions-review-78f665/ios/DashXReactNative.swift +0 -244
  54. package/.claude/worktrees/autocapture-conventions-review-78f665/ios/DashXReactNative.xcodeproj/project.pbxproj +0 -280
  55. package/.claude/worktrees/autocapture-conventions-review-78f665/ios/DashXReactNative.xcworkspace/contents.xcworkspacedata +0 -7
  56. package/.claude/worktrees/autocapture-conventions-review-78f665/ios/DashXReactNative.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  57. package/.claude/worktrees/autocapture-conventions-review-78f665/package.json +0 -123
  58. package/.claude/worktrees/autocapture-conventions-review-78f665/scripts/generate-bridge-shim.js +0 -259
  59. package/.claude/worktrees/autocapture-conventions-review-78f665/src/NativeDashXReactNative.ts +0 -42
  60. package/.claude/worktrees/autocapture-conventions-review-78f665/yarn.lock +0 -6244
  61. package/.gitattributes +0 -1
  62. package/.github/workflows/ci.yml +0 -67
  63. package/.gitignore +0 -49
  64. package/.nvmrc +0 -1
  65. package/CHANGELOG.md +0 -144
  66. package/CONTRIBUTING.md +0 -190
  67. package/__tests__/fallback.test.js +0 -72
  68. package/__tests__/index.test.js +0 -702
  69. package/android/.gitignore +0 -10
  70. package/android/.gradle/8.14.3/checksums/checksums.lock +0 -0
  71. package/android/.gradle/8.14.3/fileChanges/last-build.bin +0 -0
  72. package/android/.gradle/8.14.3/fileHashes/fileHashes.lock +0 -0
  73. package/android/.gradle/8.14.3/gc.properties +0 -0
  74. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  75. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  76. package/android/.gradle/vcs-1/gc.properties +0 -0
  77. package/android/build/reports/problems/problems-report.html +0 -663
  78. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  79. package/android/gradle/wrapper/gradle-wrapper.properties +0 -6
  80. package/android/gradlew +0 -185
  81. package/android/gradlew.bat +0 -89
  82. package/android/src/test/java/com/dashx/rn/sdk/util/UtilsTest.kt +0 -305
  83. package/babel.config.js +0 -3
  84. package/scripts/generate-bridge-shim.js +0 -259
  85. package/yarn.lock +0 -6244
@@ -1,321 +0,0 @@
1
- import { EmitterSubscription } from 'react-native';
2
-
3
- /**
4
- * Error codes returned by native SDKs in promise rejections.
5
- * Consistent across iOS and Android.
6
- */
7
- export enum DashXErrorCode {
8
- /** An unspecified error occurred. */
9
- EUNSPECIFIED = 'EUNSPECIFIED',
10
- /** The operation is not supported on this platform. */
11
- EUNSUPPORTED = 'EUNSUPPORTED',
12
- }
13
-
14
- export interface ConfigureOptions {
15
- publicKey: string;
16
- baseURI?: string;
17
- targetEnvironment?: string;
18
- }
19
-
20
- export interface IdentifyOptions {
21
- firstName?: string;
22
- lastName?: string;
23
- email?: string;
24
- phone?: string;
25
- [key: string]: string | undefined;
26
- }
27
-
28
- export type LogLevel = 0 | 1 | 2;
29
-
30
- export interface FetchRecordOptions {
31
- preview?: boolean;
32
- language?: string;
33
- fields?: Record<string, unknown>[];
34
- include?: Record<string, unknown>[];
35
- exclude?: Record<string, unknown>[];
36
- }
37
-
38
- export interface SearchRecordsOptions {
39
- filter?: Record<string, unknown>;
40
- order?: Record<string, unknown>[];
41
- limit?: number;
42
- page?: number;
43
- preview?: boolean;
44
- language?: string;
45
- fields?: Record<string, unknown>[];
46
- include?: Record<string, unknown>[];
47
- exclude?: Record<string, unknown>[];
48
- }
49
-
50
- export interface AssetData {
51
- status?: string;
52
- url?: string;
53
- playbackIds?: { id?: string; policy?: string }[];
54
- }
55
-
56
- export interface AssetResponse {
57
- status?: string;
58
- data?: { asset?: AssetData };
59
- }
60
-
61
- /**
62
- * Mirrors UNAuthorizationStatus integer values:
63
- * 0 = notDetermined, 1 = denied, 2 = authorized, 3 = provisional, 4 = ephemeral
64
- */
65
- export type NotificationPermissionStatus = 0 | 1 | 2 | 3 | 4;
66
-
67
- export interface NotificationMessage {
68
- [key: string]: unknown;
69
- }
70
-
71
- export type NavigationAction =
72
- | { type: 'deepLink'; url: string }
73
- | { type: 'screen'; name: string; data?: Record<string, string> }
74
- | { type: 'richLanding'; url: string }
75
- | { type: 'clickAction'; action: string };
76
-
77
- export interface NotificationClickedEvent {
78
- notification: NotificationMessage;
79
- action: NavigationAction | null;
80
- actionIdentifier: string;
81
- }
82
-
83
- export interface ProcessURLOptions {
84
- source?: string;
85
- forwardToLinkHandler?: boolean;
86
- }
87
-
88
- export interface NavigationRouteLike {
89
- name: string;
90
- params?: object;
91
- }
92
-
93
- /**
94
- * The subset of a React Navigation `NavigationContainer` ref used by
95
- * `trackNavigation`, so this package does not depend on `@react-navigation/*`.
96
- */
97
- export interface NavigationContainerLike {
98
- addListener(event: 'state', callback: (event: unknown) => void): () => void;
99
- getCurrentRoute(): NavigationRouteLike | undefined;
100
- isReady?(): boolean;
101
- }
102
-
103
- export interface DashXInstance {
104
- /**
105
- * Initialize the SDK with your public key and optional configuration.
106
- * Call this as early as possible, e.g. in your root component.
107
- */
108
- configure(options: ConfigureOptions): void;
109
-
110
- /**
111
- * Identify the current user with traits such as name and email.
112
- */
113
- identify(options: IdentifyOptions): void;
114
-
115
- /**
116
- * Set user identity using a UID and authentication token. Both are
117
- * nullable — passing `null` clears that field on the native SDK. Empty
118
- * strings are forwarded as-is (no coercion to `null`).
119
- */
120
- setIdentity(uid: string | null, token?: string | null): void;
121
-
122
- /**
123
- * Clear the current user identity and reset SDK state.
124
- */
125
- reset(): void;
126
-
127
- /**
128
- * Track a named event with optional metadata.
129
- */
130
- track(event: string, data?: Record<string, unknown>): void;
131
-
132
- /**
133
- * Track a screen view with optional metadata.
134
- */
135
- screen(screenName: string, data?: Record<string, unknown>): void;
136
-
137
- /**
138
- * Fetch a single record by URN (e.g. "article/123") with optional preview, language, fields, include, exclude.
139
- * Returns a promise resolving to the record object.
140
- */
141
- fetchRecord(
142
- urn: string,
143
- options?: FetchRecordOptions
144
- ): Promise<Record<string, unknown>>;
145
-
146
- /**
147
- * Search records by resource with optional filter, order, limit, preview, language, fields, include, exclude.
148
- * Returns a promise resolving to an array of record objects.
149
- */
150
- searchRecords(
151
- resource: string,
152
- options?: SearchRecordsOptions
153
- ): Promise<Record<string, unknown>[]>;
154
-
155
- /**
156
- * Subscribe the current device to push notifications.
157
- */
158
- subscribe(): void;
159
-
160
- /**
161
- * Unsubscribe the current device from push notifications.
162
- *
163
- * Resolves with `{ success: true }` when the backend found and updated a
164
- * matching subscribed contact, or `{ success: false }` when no match was
165
- * found (anonymous UID rotated since subscribe, FCM token is stale,
166
- * contact already unsubscribed, or this device never subscribed in the
167
- * current session). The device ends up unsubscribed in both cases; the
168
- * boolean is useful for diagnostics and analytics.
169
- *
170
- * Rejects on transport / SDK-state failures: native module not configured,
171
- * Firebase token-delete failure, GraphQL or network error.
172
- */
173
- unsubscribe(): Promise<{ success: boolean }>;
174
-
175
- /**
176
- * Fetch stored notification preferences for the current user.
177
- */
178
- fetchStoredPreferences(): Promise<Record<string, unknown>>;
179
-
180
- /**
181
- * Save notification preferences for the current user.
182
- */
183
- saveStoredPreferences(
184
- data: Record<string, unknown>
185
- ): Promise<Record<string, unknown>>;
186
-
187
- /**
188
- * Set SDK log verbosity. 0 = off, 1 = errors, 2 = debug.
189
- */
190
- setLogLevel(level: LogLevel): void;
191
-
192
- /**
193
- * Register a listener for incoming push notifications.
194
- * Returns a subscription that can be removed via `.remove()`.
195
- */
196
- onPushNotificationReceived(
197
- callback: (message: NotificationMessage) => void
198
- ): EmitterSubscription;
199
-
200
- /**
201
- * @deprecated Use `onPushNotificationReceived` instead.
202
- * Will be removed in the next major version.
203
- */
204
- onMessageReceived(
205
- callback: (message: NotificationMessage) => void
206
- ): EmitterSubscription;
207
-
208
- /**
209
- * Upload a local file to DashX. Returns an AssetResponse with the asset status and URL.
210
- * @param filePath Absolute path to the local file.
211
- */
212
- uploadAsset(
213
- filePath: string,
214
- resource: string,
215
- attribute: string
216
- ): Promise<AssetResponse>;
217
-
218
- /**
219
- * Fetch details of a previously uploaded asset by its ID.
220
- */
221
- fetchAsset(assetId: string): Promise<AssetResponse>;
222
-
223
- /**
224
- * Enable automatic app lifecycle events (install, update, open, background)
225
- * on iOS and Android. Call after `configure`.
226
- */
227
- enableLifecycleTracking(): void;
228
-
229
- /**
230
- * Send a screen view for each React Navigation route change. Sends the
231
- * current route once the container is ready, then `screen(route.name)`
232
- * whenever the focused route's name changes (params are not sent).
233
- * Returns a function that stops tracking.
234
- *
235
- * Call it from `NavigationContainer`'s `onReady` so the first screen is
236
- * captured. A ref from `useNavigationContainerRef()` or
237
- * `createNavigationContainerRef()` may also be passed before the container
238
- * mounts.
239
- *
240
- * @example
241
- * const navigationRef = useNavigationContainerRef();
242
- *
243
- * <NavigationContainer
244
- * ref={navigationRef}
245
- * onReady={() => DashX.trackNavigation(navigationRef)}
246
- * >
247
- * ...
248
- * </NavigationContainer>
249
- */
250
- trackNavigation(
251
- navigationRef:
252
- | NavigationContainerLike
253
- | { current: NavigationContainerLike | null }
254
- ): () => void;
255
-
256
- /**
257
- * Enable IDFA/ATT ad tracking and request the App Tracking Transparency permission (iOS only).
258
- */
259
- enableAdTracking(): void;
260
-
261
- /**
262
- * Track a deep link open event and optionally forward the URL to the link handler (iOS only).
263
- * @param url The deep link URL string.
264
- * @param options.source Optional attribution source (e.g. "universal_link", "notification").
265
- * @param options.forwardToLinkHandler Whether to forward to the link handler callback (default: true).
266
- */
267
- processURL(url: string, options?: ProcessURLOptions): void;
268
-
269
- /**
270
- * Track a notification navigation event when the user taps a notification (iOS only).
271
- * @param action The navigation action taken, or null/undefined for default.
272
- * @param notificationId Optional notification ID to associate with the event.
273
- */
274
- trackNotificationNavigation(
275
- action?: NavigationAction | null,
276
- notificationId?: string
277
- ): void;
278
-
279
- /**
280
- * Request push notification permission from the user.
281
- *
282
- * @param options.fallbackToSettings — when `true`, if the user has previously
283
- * granted or denied permission, opens the system notification settings
284
- * page so they can enable Time Sensitive notifications (or re-enable
285
- * notifications). Defaults to `false`. Use this to recover users who
286
- * granted permission before the SDK started requesting `.timeSensitive`,
287
- * since iOS won't silently add new options to an existing grant.
288
- *
289
- * Resolves with a NotificationPermissionStatus integer.
290
- */
291
- requestNotificationPermission(options?: {
292
- fallbackToSettings?: boolean
293
- }): Promise<NotificationPermissionStatus>;
294
-
295
- /**
296
- * Get the current push notification permission status without prompting.
297
- * Resolves with a NotificationPermissionStatus integer.
298
- */
299
- getNotificationPermissionStatus(): Promise<NotificationPermissionStatus>;
300
-
301
- /**
302
- * Register a listener for deep link / universal link events dispatched by the SDK.
303
- * Returns a subscription that can be removed via `.remove()`.
304
- */
305
- onLinkReceived(callback: (url: string) => void): EmitterSubscription;
306
-
307
- /**
308
- * Register a listener for notification tap events. Fired when the user taps
309
- * a DashX notification or one of its action buttons. The callback receives
310
- * the full notification payload, the resolved `NavigationAction` (parsed
311
- * from the payload; `null` if no navigation intent could be resolved), and
312
- * the raw `actionIdentifier` from `UNNotificationResponse`.
313
- * Returns a subscription that can be removed via `.remove()`.
314
- */
315
- onNotificationClicked(
316
- callback: (event: NotificationClickedEvent) => void
317
- ): EmitterSubscription;
318
- }
319
-
320
- declare const DashX: DashXInstance;
321
- export default DashX;
@@ -1,300 +0,0 @@
1
- import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
2
- import NativeDashXReactNative from './src/NativeDashXReactNative';
3
-
4
- function getLinkingError() {
5
- return (
6
- `The package 'dashx-react-native' doesn't seem to be linked. Make sure: \n\n` +
7
- Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
8
- '- You rebuilt the app after installing the package\n' +
9
- '- You are not using Expo Go\n'
10
- );
11
- }
12
-
13
- let _nativeDashX = null;
14
- function getNativeDashX() {
15
- if (!_nativeDashX) {
16
- const nativeModule =
17
- NativeDashXReactNative || NativeModules.DashXReactNative;
18
- _nativeDashX = nativeModule
19
- ? nativeModule
20
- : new Proxy(
21
- {},
22
- {
23
- get() {
24
- throw new Error(getLinkingError());
25
- },
26
- }
27
- );
28
- }
29
- return _nativeDashX;
30
- }
31
-
32
- let _onMessageReceivedDeprecationWarned = false;
33
-
34
- let _eventEmitter = null;
35
- function getEventEmitter() {
36
- if (!_eventEmitter) {
37
- _eventEmitter = new NativeEventEmitter(getNativeDashX());
38
- }
39
- return _eventEmitter;
40
- }
41
-
42
- const DashX = {
43
- configure(options) {
44
- if (!options || typeof options !== 'object') {
45
- throw new Error('DashX.configure: options must be an object');
46
- }
47
- if (!options.publicKey || typeof options.publicKey !== 'string') {
48
- throw new Error(
49
- 'DashX.configure: publicKey is required and must be a string'
50
- );
51
- }
52
- return getNativeDashX().configure(options);
53
- },
54
-
55
- identify(options) {
56
- if (!options || typeof options !== 'object') {
57
- throw new Error('DashX.identify: options must be an object');
58
- }
59
- return getNativeDashX().identify(options);
60
- },
61
-
62
- setIdentity(uid, token) {
63
- // Both uid and token are nullable passthroughs to the native SDK. Only
64
- // validate TYPE here — the native side decides semantics. `undefined` is
65
- // normalized to `null` because the RN bridge can't carry undefined.
66
- if (uid !== null && uid !== undefined && typeof uid !== 'string') {
67
- throw new Error('DashX.setIdentity: uid must be a string or null');
68
- }
69
- if (token !== null && token !== undefined && typeof token !== 'string') {
70
- throw new Error('DashX.setIdentity: token must be a string or null');
71
- }
72
- return getNativeDashX().setIdentity(uid ?? null, token ?? null);
73
- },
74
-
75
- reset() {
76
- return getNativeDashX().reset();
77
- },
78
-
79
- track(event, data) {
80
- if (!event || typeof event !== 'string') {
81
- throw new Error('DashX.track: event is required and must be a string');
82
- }
83
- return getNativeDashX().track(event, data || null);
84
- },
85
-
86
- screen(screenName, data) {
87
- if (!screenName || typeof screenName !== 'string') {
88
- throw new Error(
89
- 'DashX.screen: screenName is required and must be a string'
90
- );
91
- }
92
- return getNativeDashX().screen(screenName, data || null);
93
- },
94
-
95
- fetchRecord(urn, options = {}) {
96
- if (!urn || typeof urn !== 'string') {
97
- throw new Error(
98
- 'DashX.fetchRecord: urn is required and must be a string (e.g. "article/123")'
99
- );
100
- }
101
- if (options !== null && typeof options !== 'object') {
102
- throw new Error('DashX.fetchRecord: options must be an object');
103
- }
104
- return getNativeDashX().fetchRecord(urn, options || null);
105
- },
106
-
107
- searchRecords(resource, options = {}) {
108
- if (!resource || typeof resource !== 'string') {
109
- throw new Error(
110
- 'DashX.searchRecords: resource is required and must be a string'
111
- );
112
- }
113
- if (options !== null && typeof options !== 'object') {
114
- throw new Error('DashX.searchRecords: options must be an object');
115
- }
116
- return getNativeDashX().searchRecords(resource, options || null);
117
- },
118
-
119
- fetchStoredPreferences() {
120
- return getNativeDashX().fetchStoredPreferences();
121
- },
122
-
123
- saveStoredPreferences(preferenceData) {
124
- if (!preferenceData || typeof preferenceData !== 'object') {
125
- throw new Error(
126
- 'DashX.saveStoredPreferences: preferenceData is required and must be an object'
127
- );
128
- }
129
- return getNativeDashX().saveStoredPreferences(preferenceData);
130
- },
131
-
132
- subscribe() {
133
- return getNativeDashX().subscribe();
134
- },
135
-
136
- unsubscribe() {
137
- return getNativeDashX().unsubscribe();
138
- },
139
-
140
- setLogLevel(level) {
141
- if (typeof level !== 'number') {
142
- throw new Error('DashX.setLogLevel: level must be a number');
143
- }
144
- return getNativeDashX().setLogLevel(level);
145
- },
146
-
147
- onPushNotificationReceived(callback) {
148
- if (typeof callback !== 'function') {
149
- throw new Error(
150
- 'DashX.onPushNotificationReceived: callback must be a function'
151
- );
152
- }
153
- return getEventEmitter().addListener('messageReceived', callback);
154
- },
155
-
156
- onMessageReceived(callback) {
157
- if (!_onMessageReceivedDeprecationWarned) {
158
- console.warn(
159
- 'DashX.onMessageReceived is deprecated and will be removed in the next major version. Use DashX.onPushNotificationReceived instead.'
160
- );
161
- _onMessageReceivedDeprecationWarned = true;
162
- }
163
- return DashX.onPushNotificationReceived(callback);
164
- },
165
-
166
- uploadAsset(filePath, resource, attribute) {
167
- if (!filePath || typeof filePath !== 'string') {
168
- throw new Error('DashX.uploadAsset: filePath must be a string');
169
- }
170
- if (!resource || typeof resource !== 'string') {
171
- throw new Error('DashX.uploadAsset: resource must be a string');
172
- }
173
- if (!attribute || typeof attribute !== 'string') {
174
- throw new Error('DashX.uploadAsset: attribute must be a string');
175
- }
176
- return getNativeDashX().uploadAsset(filePath, resource, attribute);
177
- },
178
-
179
- fetchAsset(assetId) {
180
- if (!assetId || typeof assetId !== 'string') {
181
- throw new Error('DashX.fetchAsset: assetId must be a string');
182
- }
183
- return getNativeDashX().fetchAsset(assetId);
184
- },
185
-
186
- enableLifecycleTracking() {
187
- return getNativeDashX().enableLifecycleTracking();
188
- },
189
-
190
- trackNavigation(navigationRef) {
191
- if (!navigationRef || typeof navigationRef !== 'object') {
192
- throw new Error(
193
- 'DashX.trackNavigation: navigationRef must be a NavigationContainer ref'
194
- );
195
- }
196
-
197
- // A ref from createNavigationContainerRef / useNavigationContainerRef
198
- // queues listeners until the container mounts; a plain useRef does not.
199
- const navigation =
200
- typeof navigationRef.addListener === 'function'
201
- ? navigationRef
202
- : navigationRef.current;
203
-
204
- if (!navigation) {
205
- console.warn(
206
- 'DashX.trackNavigation: navigationRef.current is null. Call it from NavigationContainer onReady, or pass a ref from useNavigationContainerRef().'
207
- );
208
- return () => {};
209
- }
210
- if (
211
- typeof navigation.addListener !== 'function' ||
212
- typeof navigation.getCurrentRoute !== 'function'
213
- ) {
214
- throw new Error(
215
- 'DashX.trackNavigation: navigationRef must be a NavigationContainer ref'
216
- );
217
- }
218
-
219
- let lastRouteName = null;
220
- let active = true;
221
-
222
- const trackCurrentRoute = () => {
223
- if (!active) return;
224
- // getCurrentRoute() logs an error on a container ref that is not ready.
225
- if (typeof navigation.isReady === 'function' && !navigation.isReady()) {
226
- return;
227
- }
228
- const route = navigation.getCurrentRoute();
229
- const routeName = route && route.name;
230
- if (!routeName || routeName === lastRouteName) return;
231
- lastRouteName = routeName;
232
- DashX.screen(routeName);
233
- };
234
-
235
- const removeListener = navigation.addListener('state', trackCurrentRoute);
236
- trackCurrentRoute();
237
-
238
- return () => {
239
- active = false;
240
- if (typeof removeListener === 'function') removeListener();
241
- };
242
- },
243
-
244
- enableAdTracking() {
245
- if (Platform.OS !== 'ios') return;
246
- return getNativeDashX().enableAdTracking();
247
- },
248
-
249
- processURL(url, options = {}) {
250
- if (Platform.OS !== 'ios') return;
251
- if (!url || typeof url !== 'string') {
252
- throw new Error('DashX.processURL: url is required and must be a string');
253
- }
254
- return getNativeDashX().processURL(
255
- url,
256
- options.source || null,
257
- options.forwardToLinkHandler !== false
258
- );
259
- },
260
-
261
- trackNotificationNavigation(action, notificationId) {
262
- if (Platform.OS !== 'ios') return;
263
- if (action != null && typeof action !== 'object') {
264
- throw new Error(
265
- 'DashX.trackNotificationNavigation: action must be an object or null'
266
- );
267
- }
268
- return getNativeDashX().trackNotificationNavigation(
269
- action || null,
270
- notificationId || null
271
- );
272
- },
273
-
274
- requestNotificationPermission(options) {
275
- const fallbackToSettings = Boolean(options && options.fallbackToSettings);
276
- return getNativeDashX().requestNotificationPermission(fallbackToSettings);
277
- },
278
-
279
- getNotificationPermissionStatus() {
280
- return getNativeDashX().getNotificationPermissionStatus();
281
- },
282
-
283
- onLinkReceived(callback) {
284
- if (typeof callback !== 'function') {
285
- throw new Error('DashX.onLinkReceived: callback must be a function');
286
- }
287
- return getEventEmitter().addListener('linkReceived', callback);
288
- },
289
-
290
- onNotificationClicked(callback) {
291
- if (typeof callback !== 'function') {
292
- throw new Error(
293
- 'DashX.onNotificationClicked: callback must be a function'
294
- );
295
- }
296
- return getEventEmitter().addListener('notificationClicked', callback);
297
- },
298
- };
299
-
300
- export default DashX;
@@ -1,15 +0,0 @@
1
- class DashXEventEmitter {
2
- static let instance = DashXEventEmitter()
3
- private static var eventEmitter: DashXReactNative?
4
-
5
- private init() {}
6
-
7
- func registerEventEmitter(eventEmitter: DashXReactNative) {
8
- DashXEventEmitter.eventEmitter = eventEmitter
9
- }
10
-
11
- func dispatch(name: String, body: Any?) {
12
- guard let emitter = DashXEventEmitter.eventEmitter else { return }
13
- emitter.sendEvent(withName: name, body: body)
14
- }
15
- }