cm-sdk-react-native-v3 3.5.3 → 3.6.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 (28) hide show
  1. package/README.md +13 -1
  2. package/android/build.gradle +5 -5
  3. package/android/gradle.properties +3 -3
  4. package/android/src/main/java/com/cmsdkreactnativev3/CmSdkReactNativeV3Module.kt +43 -139
  5. package/android/src/main/java/com/cmsdkreactnativev3/CmSdkReactNativeV3Package.kt +24 -4
  6. package/ios/CmSdkReactNativeV3-Bridging-Header.h +4 -0
  7. package/ios/CmSdkReactNativeV3.mm +42 -76
  8. package/ios/CmSdkReactNativeV3.swift +37 -120
  9. package/lib/commonjs/NativeCmSdkReactNativeV3.js +11 -0
  10. package/lib/commonjs/NativeCmSdkReactNativeV3.js.map +1 -0
  11. package/lib/commonjs/index.js +108 -36
  12. package/lib/commonjs/index.js.map +1 -1
  13. package/lib/module/NativeCmSdkReactNativeV3.js +10 -0
  14. package/lib/module/NativeCmSdkReactNativeV3.js.map +1 -0
  15. package/lib/module/index.js +86 -34
  16. package/lib/module/index.js.map +1 -1
  17. package/lib/typescript/commonjs/src/NativeCmSdkReactNativeV3.d.ts +68 -0
  18. package/lib/typescript/commonjs/src/NativeCmSdkReactNativeV3.d.ts.map +1 -0
  19. package/lib/typescript/commonjs/src/index.d.ts +25 -32
  20. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  21. package/lib/typescript/module/src/NativeCmSdkReactNativeV3.d.ts +68 -0
  22. package/lib/typescript/module/src/NativeCmSdkReactNativeV3.d.ts.map +1 -0
  23. package/lib/typescript/module/src/index.d.ts +25 -32
  24. package/lib/typescript/module/src/index.d.ts.map +1 -1
  25. package/package.json +8 -2
  26. package/react-native-cm-sdk-react-native-v3.podspec +1 -1
  27. package/src/NativeCmSdkReactNativeV3.ts +92 -0
  28. package/src/index.tsx +125 -39
package/src/index.tsx CHANGED
@@ -1,4 +1,14 @@
1
1
  import { NativeModules, Platform, NativeEventEmitter } from 'react-native';
2
+ import NativeCmSdkReactNativeV3, {
3
+ type ConsentReceivedEvent,
4
+ type ErrorEvent,
5
+ type LinkClickEvent,
6
+ type ATTStatusChangeEvent,
7
+ type UrlConfig,
8
+ type WebViewConfig,
9
+ type UserStatus,
10
+ type GoogleConsentModeStatus,
11
+ } from './NativeCmSdkReactNativeV3';
2
12
 
3
13
  const LINKING_ERROR =
4
14
  `The package 'react-native-cm-sdk-react-native-v3' doesn't seem to be linked. Make sure: \n\n` +
@@ -6,7 +16,8 @@ const LINKING_ERROR =
6
16
  '- You rebuilt the app after installing the package\n' +
7
17
  '- You are not using Expo Go\n';
8
18
 
9
- const CmSdkReactNativeV3 = NativeModules.CmSdkReactNativeV3
19
+ // Use TurboModule if available (New Architecture), fallback to legacy NativeModules
20
+ const CmSdkReactNativeV3 = NativeCmSdkReactNativeV3 ?? (NativeModules.CmSdkReactNativeV3
10
21
  ? NativeModules.CmSdkReactNativeV3
11
22
  : new Proxy(
12
23
  {},
@@ -15,14 +26,16 @@ const CmSdkReactNativeV3 = NativeModules.CmSdkReactNativeV3
15
26
  throw new Error(LINKING_ERROR);
16
27
  },
17
28
  }
18
- );
29
+ ));
30
+
31
+ export const isTurboModuleEnabled = NativeCmSdkReactNativeV3 != null;
19
32
 
20
33
  const eventEmitter = new NativeEventEmitter(CmSdkReactNativeV3);
21
34
 
22
35
  export const addConsentListener = (
23
- callback: (consent: string, jsonObject: any) => void
36
+ callback: (consent: string, jsonObject: Object) => void
24
37
  ) => {
25
- return eventEmitter.addListener('didReceiveConsent', (event) => {
38
+ return eventEmitter.addListener('didReceiveConsent', (event: ConsentReceivedEvent) => {
26
39
  callback(event.consent, event.jsonObject);
27
40
  });
28
41
  };
@@ -36,55 +49,128 @@ export const addCloseConsentLayerListener = (callback: () => void) => {
36
49
  };
37
50
 
38
51
  export const addErrorListener = (callback: (error: string) => void) => {
39
- return eventEmitter.addListener('didReceiveError', (event) => {
52
+ return eventEmitter.addListener('didReceiveError', (event: ErrorEvent) => {
40
53
  callback(event.error);
41
54
  });
42
55
  };
43
56
 
44
57
  export const addClickLinkListener = (callback: (url: string) => void) => {
45
- return eventEmitter.addListener('onClickLink', (event) => {
58
+ return eventEmitter.addListener('onClickLink', (event: LinkClickEvent) => {
46
59
  callback(event.url);
47
60
  });
48
61
  };
49
62
 
63
+ export const addATTStatusChangeListener = (callback: (event: ATTStatusChangeEvent) => void) => {
64
+ return eventEmitter.addListener('didChangeATTStatus', callback);
65
+ };
66
+
50
67
  // Core configuration methods
51
- export const setUrlConfig = CmSdkReactNativeV3.setUrlConfig;
52
- export const setWebViewConfig = CmSdkReactNativeV3.setWebViewConfig;
68
+ export const setUrlConfig = (config: UrlConfig): Promise<void> => {
69
+ return CmSdkReactNativeV3.setUrlConfig(config);
70
+ };
71
+
72
+ export const setWebViewConfig = (config: WebViewConfig): Promise<void> => {
73
+ return CmSdkReactNativeV3.setWebViewConfig(config);
74
+ };
53
75
 
54
- // Main interaction methods (new API)
55
- export const checkAndOpen = CmSdkReactNativeV3.checkAndOpen;
56
- export const forceOpen = CmSdkReactNativeV3.forceOpen;
57
- export const jumpToSettings = CmSdkReactNativeV3.jumpToSettings;
76
+ export const setATTStatus = (status: number): Promise<void> => {
77
+ return CmSdkReactNativeV3.setATTStatus(status);
78
+ };
79
+
80
+ // Main interaction methods
81
+ export const checkAndOpen = (jumpToSettings: boolean): Promise<boolean> => {
82
+ return CmSdkReactNativeV3.checkAndOpen(jumpToSettings);
83
+ };
84
+
85
+ export const forceOpen = (jumpToSettings: boolean): Promise<boolean> => {
86
+ return CmSdkReactNativeV3.forceOpen(jumpToSettings);
87
+ };
58
88
 
59
89
  // Consent status methods
60
- export const getUserStatus = CmSdkReactNativeV3.getUserStatus;
61
- export const getStatusForPurpose = CmSdkReactNativeV3.getStatusForPurpose;
62
- export const getStatusForVendor = CmSdkReactNativeV3.getStatusForVendor;
63
- export const getGoogleConsentModeStatus = CmSdkReactNativeV3.getGoogleConsentModeStatus;
64
- export const exportCMPInfo = CmSdkReactNativeV3.exportCMPInfo;
65
- export const importCMPInfo = CmSdkReactNativeV3.importCMPInfo;
66
- export const resetConsentManagementData = CmSdkReactNativeV3.resetConsentManagementData;
90
+ export const getUserStatus = (): Promise<UserStatus> => {
91
+ return CmSdkReactNativeV3.getUserStatus();
92
+ };
93
+
94
+ export const getStatusForPurpose = (purposeId: string): Promise<string> => {
95
+ return CmSdkReactNativeV3.getStatusForPurpose(purposeId);
96
+ };
97
+
98
+ export const getStatusForVendor = (vendorId: string): Promise<string> => {
99
+ return CmSdkReactNativeV3.getStatusForVendor(vendorId);
100
+ };
101
+
102
+ export const getGoogleConsentModeStatus = (): Promise<GoogleConsentModeStatus> => {
103
+ return CmSdkReactNativeV3.getGoogleConsentModeStatus();
104
+ };
105
+
106
+ export const exportCMPInfo = (): Promise<string> => {
107
+ return CmSdkReactNativeV3.exportCMPInfo();
108
+ };
109
+
110
+ export const importCMPInfo = (cmpString: string): Promise<boolean> => {
111
+ return CmSdkReactNativeV3.importCMPInfo(cmpString);
112
+ };
113
+
114
+ export const resetConsentManagementData = (): Promise<boolean> => {
115
+ return CmSdkReactNativeV3.resetConsentManagementData();
116
+ };
67
117
 
68
118
  // Consent modification methods
69
- export const acceptVendors = CmSdkReactNativeV3.acceptVendors;
70
- export const rejectVendors = CmSdkReactNativeV3.rejectVendors;
71
- export const acceptPurposes = CmSdkReactNativeV3.acceptPurposes;
72
- export const rejectPurposes = CmSdkReactNativeV3.rejectPurposes;
73
- export const rejectAll = CmSdkReactNativeV3.rejectAll;
74
- export const acceptAll = CmSdkReactNativeV3.acceptAll;
75
-
76
- // Deprecated methods (kept for backward compatibility)
77
- export const checkWithServerAndOpenIfNecessary = CmSdkReactNativeV3.checkWithServerAndOpenIfNecessary;
78
- export const openConsentLayer = CmSdkReactNativeV3.openConsentLayer;
79
- export const checkIfConsentIsRequired = CmSdkReactNativeV3.checkIfConsentIsRequired;
80
- export const hasUserChoice = CmSdkReactNativeV3.hasUserChoice;
81
- export const hasPurposeConsent = CmSdkReactNativeV3.hasPurposeConsent;
82
- export const hasVendorConsent = CmSdkReactNativeV3.hasVendorConsent;
83
- export const getAllPurposesIDs = CmSdkReactNativeV3.getAllPurposesIDs;
84
- export const getEnabledPurposesIDs = CmSdkReactNativeV3.getEnabledPurposesIDs;
85
- export const getDisabledPurposesIDs = CmSdkReactNativeV3.getDisabledPurposesIDs;
86
- export const getAllVendorsIDs = CmSdkReactNativeV3.getAllVendorsIDs;
87
- export const getEnabledVendorsIDs = CmSdkReactNativeV3.getEnabledVendorsIDs;
88
- export const getDisabledVendorsIDs = CmSdkReactNativeV3.getDisabledVendorsIDs;
119
+ export const acceptVendors = (vendors: string[]): Promise<boolean> => {
120
+ return CmSdkReactNativeV3.acceptVendors(vendors);
121
+ };
122
+
123
+ export const rejectVendors = (vendors: string[]): Promise<boolean> => {
124
+ return CmSdkReactNativeV3.rejectVendors(vendors);
125
+ };
126
+
127
+ export const acceptPurposes = (purposes: string[], updatePurpose: boolean): Promise<boolean> => {
128
+ return CmSdkReactNativeV3.acceptPurposes(purposes, updatePurpose);
129
+ };
130
+
131
+ export const rejectPurposes = (purposes: string[], updateVendor: boolean): Promise<boolean> => {
132
+ return CmSdkReactNativeV3.rejectPurposes(purposes, updateVendor);
133
+ };
134
+
135
+ export const rejectAll = (): Promise<boolean> => {
136
+ return CmSdkReactNativeV3.rejectAll();
137
+ };
138
+
139
+ export const acceptAll = (): Promise<boolean> => {
140
+ return CmSdkReactNativeV3.acceptAll();
141
+ };
142
+
143
+ // Helper function to check if New Architecture is enabled
144
+ export const isNewArchitectureEnabled = (): boolean => {
145
+ // Check multiple indicators for New Architecture
146
+ // 1. Check if our module was loaded via TurboModuleRegistry
147
+ if (NativeCmSdkReactNativeV3 != null) {
148
+ return true;
149
+ }
150
+
151
+ // 2. Check for bridgeless mode (official RN flag)
152
+ if ((global as any).RN$Bridgeless === true) {
153
+ return true;
154
+ }
155
+
156
+ // 3. Check for TurboModule interop flag
157
+ if ((global as any).RN$TurboInterop === true) {
158
+ return true;
159
+ }
160
+
161
+ return false;
162
+ };
163
+
164
+ // Re-export types for consumer convenience
165
+ export type {
166
+ ConsentReceivedEvent,
167
+ ErrorEvent,
168
+ LinkClickEvent,
169
+ ATTStatusChangeEvent,
170
+ UrlConfig,
171
+ WebViewConfig,
172
+ UserStatus,
173
+ GoogleConsentModeStatus,
174
+ };
89
175
 
90
176
  export default CmSdkReactNativeV3;