react-native-insider 7.1.0 → 8.0.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.
package/README.md CHANGED
@@ -707,3 +707,4 @@ function App() {
707
707
  ## License
708
708
 
709
709
  This SDK is provided by Insider. Please refer to your commercial agreement with Insider for licensing terms.
710
+ # Test
package/RNInsider.podspec CHANGED
@@ -9,12 +9,12 @@ Pod::Spec.new do |s|
9
9
  s.authors = package_json['author']
10
10
  s.license = 'MIT'
11
11
  s.platform = :ios, '12.0'
12
- s.source = {:http => 'https://mobilesdk.useinsider.com/iOS/14.3.1/InsiderMobileIOSFramework.zip'}
12
+ s.source = {:http => 'https://mobilesdk.useinsider.com/iOS/15.0.0/InsiderMobileIOSFramework.zip'}
13
13
  s.source_files = 'ios/RNInsider/*.{h,m}'
14
14
  s.requires_arc = true
15
15
  s.static_framework = true
16
16
  s.dependency 'React'
17
- s.dependency 'InsiderMobile', '14.3.1'
17
+ s.dependency 'InsiderMobile', '15.0.0'
18
18
  s.dependency 'InsiderGeofence', '1.2.4'
19
19
  s.dependency 'InsiderHybrid', '1.7.6'
20
20
  end
@@ -42,7 +42,7 @@ repositories {
42
42
 
43
43
  dependencies {
44
44
  implementation "com.facebook.react:react-native:${getVersionFromPartner('reactNativeVersion', '+')}"
45
- implementation 'com.useinsider:insider:15.3.0'
45
+ implementation 'com.useinsider:insider:16.0.1'
46
46
  implementation 'com.useinsider:insiderhybrid:1.3.4'
47
47
 
48
48
  implementation 'androidx.security:security-crypto:1.1.0-alpha06'
@@ -21,6 +21,9 @@ import com.useinsider.insider.InsiderCallback;
21
21
  import com.useinsider.insider.InsiderCallbackType;
22
22
  import com.useinsider.insider.InsiderIdentifiers;
23
23
  import com.useinsider.insider.InsiderUser;
24
+ import com.useinsider.insider.AppCardsException;
25
+ import com.useinsider.insider.InsiderAppCardButton;
26
+ import com.useinsider.insider.InsiderAppCard;
24
27
  import com.useinsider.insider.InsiderProduct;
25
28
  import com.useinsider.insider.CloseButtonPosition;
26
29
  import com.useinsider.insider.MessageCenterData;
@@ -498,11 +501,13 @@ public class RNInsiderModule extends ReactContextBaseJavaModule {
498
501
  }
499
502
 
500
503
  @ReactMethod
501
- public void itemRemovedFromCart(String productID, ReadableArray customParameters) {
504
+ public void itemRemovedFromCart(String productID, String saleID, ReadableArray customParameters) {
502
505
  try {
503
506
  Map<String, Object> mappedCustomParameters = RNUtils.parseCustomParameters(customParameters);
504
507
 
505
- if (!mappedCustomParameters.isEmpty()) {
508
+ if (saleID != null && saleID.length() > 0) {
509
+ Insider.Instance.itemRemovedFromCart(productID, saleID, mappedCustomParameters);
510
+ } else if (!mappedCustomParameters.isEmpty()) {
506
511
  Insider.Instance.itemRemovedFromCart(productID, mappedCustomParameters);
507
512
  } else {
508
513
  Insider.Instance.itemRemovedFromCart(productID);
@@ -595,6 +600,32 @@ public class RNInsiderModule extends ReactContextBaseJavaModule {
595
600
  }
596
601
  }
597
602
 
603
+ @ReactMethod
604
+ public void getMessageCenterDataWithIdentifiers(int limit, String startDate, String endDate, ReadableMap identifiers, final Callback messageCenterCallback) {
605
+ long startDateEpoch = Long.parseLong(startDate);
606
+ long endDateEpoch = Long.parseLong(endDate);
607
+
608
+ try {
609
+ Insider.Instance.getMessageCenterData(
610
+ limit,
611
+ new Date(startDateEpoch),
612
+ new Date(endDateEpoch),
613
+ setIdentifiers(identifiers),
614
+ new MessageCenterData() {
615
+ @Override
616
+ public void loadMessageCenterData(JSONArray messageCenterData) {
617
+ try {
618
+ messageCenterCallback.invoke(RNUtils.convertJSONArrayToArray(messageCenterData).toString());
619
+ } catch (Exception e) {
620
+ Insider.Instance.putException(e);
621
+ }
622
+ }
623
+ });
624
+ } catch (Exception e) {
625
+ Insider.Instance.putException(e);
626
+ }
627
+ }
628
+
598
629
  @ReactMethod
599
630
  public void getSmartRecommendation(int recommendationID, String locale, String currency,
600
631
  final Callback smartRecommendation) {
@@ -776,7 +807,7 @@ public class RNInsiderModule extends ReactContextBaseJavaModule {
776
807
  }
777
808
 
778
809
  @ReactMethod
779
- public void visitCartPage(ReadableArray products, ReadableArray customParameters) {
810
+ public void visitCartPage(ReadableArray products, String saleID, ReadableArray customParameters) {
780
811
  try {
781
812
  InsiderProduct[] ips = new InsiderProduct[products.size()];
782
813
  for (int i = 0; i < products.size(); i++) {
@@ -790,7 +821,9 @@ public class RNInsiderModule extends ReactContextBaseJavaModule {
790
821
 
791
822
  Map<String, Object> mappedCustomParameters = RNUtils.parseCustomParameters(customParameters);
792
823
 
793
- if (!mappedCustomParameters.isEmpty()) {
824
+ if (saleID != null && saleID.length() > 0) {
825
+ Insider.Instance.visitCartPage(ips, saleID, mappedCustomParameters);
826
+ } else if (!mappedCustomParameters.isEmpty()) {
794
827
  Insider.Instance.visitCartPage(ips, mappedCustomParameters);
795
828
  } else {
796
829
  Insider.Instance.visitCartPage(ips);
@@ -1055,4 +1088,112 @@ public class RNInsiderModule extends ReactContextBaseJavaModule {
1055
1088
  Insider.Instance.putException(e);
1056
1089
  }
1057
1090
  }
1091
+
1092
+ @ReactMethod
1093
+ public void getAppCardsCampaigns(final Callback callback) {
1094
+ try {
1095
+ Insider.Instance.appCards().getCampaigns((responseObject, error) -> {
1096
+ if (error != null || responseObject == null) {
1097
+ WritableMap errorDetails = RNUtils.appCardsErrorToMap(error);
1098
+ callback.invoke(errorDetails);
1099
+ } else {
1100
+ JSONObject jsonObject = responseObject.toJSONObject();
1101
+ WritableMap writableMap = RNUtils.convertJSONObjectToMap(jsonObject);
1102
+ callback.invoke(null, writableMap);
1103
+ }
1104
+ });
1105
+ } catch (Exception e) {
1106
+ callback.invoke(RNUtils.appCardsErrorToMap(null));
1107
+ Insider.Instance.putException(e);
1108
+ }
1109
+ }
1110
+
1111
+ @ReactMethod
1112
+ public void markAppCardsAsRead(final ReadableArray appCardIds, final Callback callback) {
1113
+ try {
1114
+ String[] array = RNUtils.convertReadableArrayToStringArray(appCardIds);
1115
+ Insider.Instance.appCards().markAsRead(array, error -> {
1116
+ if (error != null) {
1117
+ WritableMap errorDetails = RNUtils.appCardsErrorToMap(error);
1118
+ callback.invoke(errorDetails);
1119
+ } else {
1120
+ callback.invoke();
1121
+ }
1122
+ });
1123
+ } catch (Exception e) {
1124
+ callback.invoke(RNUtils.appCardsErrorToMap(null));
1125
+ Insider.Instance.putException(e);
1126
+ }
1127
+ }
1128
+
1129
+ @ReactMethod
1130
+ public void markAppCardsAsUnread(final ReadableArray appCardIds, final Callback callback) {
1131
+ try {
1132
+ String[] array = RNUtils.convertReadableArrayToStringArray(appCardIds);
1133
+ Insider.Instance.appCards().markAsUnread(array, error -> {
1134
+ if (error != null) {
1135
+ WritableMap errorDetails = RNUtils.appCardsErrorToMap(error);
1136
+ callback.invoke(errorDetails);
1137
+ } else {
1138
+ callback.invoke();
1139
+ }
1140
+ });
1141
+ } catch (Exception e) {
1142
+ callback.invoke(RNUtils.appCardsErrorToMap(null));
1143
+ Insider.Instance.putException(e);
1144
+ }
1145
+ }
1146
+
1147
+ @ReactMethod
1148
+ public void deleteAppCards(final ReadableArray appCardIds, final Callback callback) {
1149
+ try {
1150
+ String[] array = RNUtils.convertReadableArrayToStringArray(appCardIds);
1151
+ Insider.Instance.appCards().delete(array, error -> {
1152
+ if (error != null) {
1153
+ WritableMap errorDetails = RNUtils.appCardsErrorToMap(error);
1154
+ callback.invoke(errorDetails);
1155
+ } else {
1156
+ callback.invoke();
1157
+ }
1158
+ });
1159
+ } catch (Exception e) {
1160
+ callback.invoke(RNUtils.appCardsErrorToMap(null));
1161
+ Insider.Instance.putException(e);
1162
+ }
1163
+ }
1164
+
1165
+ @ReactMethod
1166
+ public void clickAppCardButton(final String appCardId, final ReadableMap data) {
1167
+ try {
1168
+ HashMap<String, Object> map = RNUtils.convertReadableMapToMap(data);
1169
+ JSONObject jsonObject = new JSONObject(map);
1170
+ new InsiderAppCardButton(appCardId, jsonObject).click();
1171
+ } catch (Exception e) {
1172
+ Insider.Instance.putException(e);
1173
+ }
1174
+ }
1175
+
1176
+ @ReactMethod
1177
+ public void viewAppCard(final ReadableMap data) {
1178
+ try {
1179
+ HashMap<String, Object> map = RNUtils.convertReadableMapToMap(data);
1180
+ JSONObject jsonObject = new JSONObject(map);
1181
+
1182
+ new InsiderAppCard(jsonObject).view();
1183
+ } catch (Exception e) {
1184
+ Insider.Instance.putException(e);
1185
+ }
1186
+ }
1187
+
1188
+ @ReactMethod
1189
+ public void clickAppCard(final ReadableMap data) {
1190
+ try {
1191
+ HashMap<String, Object> map = RNUtils.convertReadableMapToMap(data);
1192
+ JSONObject jsonObject = new JSONObject(map);
1193
+
1194
+ new InsiderAppCard(jsonObject).click();
1195
+ } catch (Exception e) {
1196
+ Insider.Instance.putException(e);
1197
+ }
1198
+ }
1058
1199
  }
@@ -8,6 +8,7 @@ import com.facebook.react.bridge.WritableArray;
8
8
  import com.facebook.react.bridge.WritableMap;
9
9
  import com.facebook.react.bridge.WritableNativeArray;
10
10
  import com.facebook.react.bridge.WritableNativeMap;
11
+ import com.useinsider.insider.AppCardsException;
11
12
  import com.useinsider.insider.Insider;
12
13
  import com.useinsider.insider.InsiderEvent;
13
14
  import com.useinsider.insider.InsiderProduct;
@@ -36,7 +37,7 @@ public class RNUtils {
36
37
  return writableMap;
37
38
  }
38
39
 
39
- public static WritableArray convertJSONArrayToArray(JSONArray jsonArray) throws JSONException {
40
+ public static WritableArray convertJSONArrayToArray(JSONArray jsonArray) {
40
41
  WritableArray array = new WritableNativeArray();
41
42
  try {
42
43
  for (int i = 0; i < jsonArray.length(); i++) {
@@ -63,7 +64,7 @@ public class RNUtils {
63
64
  return array;
64
65
  }
65
66
 
66
- public static WritableMap convertJSONObjectToMap(JSONObject jsonObject) throws JSONException {
67
+ public static WritableMap convertJSONObjectToMap(JSONObject jsonObject) {
67
68
  WritableMap map = new WritableNativeMap();
68
69
  try {
69
70
  Iterator<String> iterator = jsonObject.keys();
@@ -380,6 +381,24 @@ public class RNUtils {
380
381
  return product;
381
382
  }
382
383
 
384
+ public static String mapAppCardsExceptionCode(AppCardsException exception) {
385
+ switch (exception.getCode()) {
386
+ case SDK_NOT_INITIALIZED: return "sdkNotInitialized";
387
+ case INVALID_PARAMETER: return "invalidParameter";
388
+ case NETWORK_ERROR: return "networkError";
389
+ case SERVER_ERROR: return "serverError";
390
+ case PARSE_ERROR: return "parseError";
391
+ default: return "unknown";
392
+ }
393
+ }
394
+
395
+ public static WritableMap appCardsErrorToMap(AppCardsException error) {
396
+ WritableMap map = new WritableNativeMap();
397
+ map.putString("code", error != null ? mapAppCardsExceptionCode(error) : "unknown");
398
+ map.putString("message", error != null && error.getMessage() != null ? error.getMessage() : "An unexpected error occurred.");
399
+ return map;
400
+ }
401
+
383
402
  public static Map<String, Object> parseCustomParameters(ReadableArray customParameters) {
384
403
  Map<String, Object> mappedCustomParameters = new HashMap<>();
385
404
  try {
package/index.d.ts CHANGED
@@ -1,11 +1,89 @@
1
1
  import type RNInsiderProduct from './src/InsiderProduct';
2
2
  import type RNInsiderEvent from './src/InsiderEvent';
3
3
  import type RNInsiderUser from './src/InsiderUser';
4
+ import type RNInsiderIdentifier from './src/InsiderIdentifier';
5
+ import type RNInsiderAppCards from './src/InsiderAppCards';
4
6
 
5
7
  export type CustomParameters = {
6
8
  [key: string]: string | number | boolean | Date | number[] | string[];
7
9
  };
8
10
 
11
+ /**
12
+ * Error codes for App Cards operations.
13
+ *
14
+ * These codes are aligned with the native SDK error codes on both Android and iOS:
15
+ * - Android: AppCardsException.AppCardsExceptionCode
16
+ * - iOS: InsiderAppCardsErrorCode
17
+ *
18
+ * @readonly
19
+ * @enum {string}
20
+ */
21
+ export declare const InsiderAppCardsErrorCode: {
22
+ /** An unknown or unexpected error occurred. */
23
+ readonly UNKNOWN: 'unknown';
24
+ /** The Insider SDK is not initialized, frozen, or not GDPR compliant. */
25
+ readonly SDK_NOT_INITIALIZED: 'sdkNotInitialized';
26
+ /** An invalid parameter was provided (e.g., empty or null IDs). */
27
+ readonly INVALID_PARAMETER: 'invalidParameter';
28
+ /** A network error occurred during the request. */
29
+ readonly NETWORK_ERROR: 'networkError';
30
+ /** The server returned an error response. */
31
+ readonly SERVER_ERROR: 'serverError';
32
+ /** The server response could not be parsed. */
33
+ readonly PARSE_ERROR: 'parseError';
34
+ };
35
+
36
+ /** Union type of all possible error code values. */
37
+ export type InsiderAppCardsErrorCodeType = typeof InsiderAppCardsErrorCode[keyof typeof InsiderAppCardsErrorCode];
38
+
39
+ /**
40
+ * Represents a typed error from an App Cards operation.
41
+ *
42
+ * Extends the standard Error class with a structured error code
43
+ * that maps to the native SDK error codes on both Android and iOS.
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * try {
48
+ * const response = await RNInsider.appCards.getCampaigns();
49
+ * } catch (error) {
50
+ * if (error instanceof InsiderAppCardsError) {
51
+ * switch (error.code) {
52
+ * case InsiderAppCardsErrorCode.NETWORK_ERROR:
53
+ * console.log('Network issue, please try again');
54
+ * break;
55
+ * case InsiderAppCardsErrorCode.SDK_NOT_INITIALIZED:
56
+ * console.log('SDK not ready');
57
+ * break;
58
+ * default:
59
+ * console.log('Error:', error.code, error.message);
60
+ * }
61
+ * }
62
+ * }
63
+ * ```
64
+ */
65
+ export declare class InsiderAppCardsError extends Error {
66
+ /** The name of the error, always 'InsiderAppCardsError'. */
67
+ readonly name: 'InsiderAppCardsError';
68
+
69
+ /** The error code identifying the type of error. */
70
+ readonly code: InsiderAppCardsErrorCodeType;
71
+
72
+ /**
73
+ * @param code - One of InsiderAppCardsErrorCode values.
74
+ * @param message - A human-readable error description.
75
+ */
76
+ constructor(code: InsiderAppCardsErrorCodeType, message: string);
77
+
78
+ /**
79
+ * Creates an InsiderAppCardsError from a native bridge error response.
80
+ *
81
+ * @param error - The error from the native bridge, either a structured object or a plain string.
82
+ * @returns A new InsiderAppCardsError instance.
83
+ */
84
+ static from(error: { code: string; message: string } | string | unknown): InsiderAppCardsError;
85
+ }
86
+
9
87
  declare module 'react-native-insider' {
10
88
  export interface InsiderCloseButtonPosition {
11
89
  LEFT: string;
@@ -15,11 +93,14 @@ declare module 'react-native-insider' {
15
93
 
16
94
  export default class RNInsider {
17
95
  static closeButtonPosition: InsiderCloseButtonPosition;
96
+ static AppCardsError: typeof InsiderAppCardsError;
97
+ static AppCardsErrorCode: typeof InsiderAppCardsErrorCode;
18
98
  static init(partnerName: string, appGroup: string, insiderCallback: Function): void;
19
99
  static initWithCustomEndpoint(partnerName: string, appGroup: string, endpoint: string, insiderCallback: Function): void;
20
100
  static reinitWithPartnerName(partnerName: string): void;
21
101
  static tagEvent(name: string): RNInsiderEvent;
22
102
  static getCurrentUser(): RNInsiderUser;
103
+ static get appCards(): RNInsiderAppCards;
23
104
  static setGDPRConsent(gdprConsent: boolean): void;
24
105
  static setMobileAppAccess(mobileAppAccess: boolean): void;
25
106
 
@@ -33,7 +114,10 @@ declare module 'react-native-insider' {
33
114
  ): RNInsiderProduct;
34
115
  static itemPurchased(uniqueSaleID: string, product: RNInsiderProduct, customParameters?: CustomParameters): void;
35
116
  static itemAddedToCart(product: RNInsiderProduct, customParameters?: CustomParameters): void;
36
- static itemRemovedFromCart(productID: string, customParameters?: CustomParameters): void;
117
+ static itemRemovedFromCart(productID: string): void;
118
+ static itemRemovedFromCart(productID: string, customParameters: CustomParameters): void;
119
+ static itemRemovedFromCart(productID: string, saleID: string): void;
120
+ static itemRemovedFromCart(productID: string, saleID: string, customParameters: CustomParameters): void;
37
121
  static cartCleared(customParameters?: CustomParameters): void;
38
122
  static itemAddedToWishlist(product: RNInsiderProduct, customParameters?: CustomParameters): void;
39
123
  static itemRemovedFromWishlist(productID: string, customParameters?: CustomParameters): void;
@@ -44,6 +128,13 @@ declare module 'react-native-insider' {
44
128
  endDate: Date,
45
129
  callback: (messageCenterData: any) => void
46
130
  ): void;
131
+ static getMessageCenterDataWithIdentifiers(
132
+ limit: number,
133
+ startDate: Date,
134
+ endDate: Date,
135
+ identifiers: RNInsiderIdentifier,
136
+ callback: (messageCenterData: any) => void
137
+ ): void;
47
138
  static getSmartRecommendation(
48
139
  recommendationID: number,
49
140
  locale: string,
@@ -103,7 +194,10 @@ declare module 'react-native-insider' {
103
194
  static visitHomePage(customParameters?: CustomParameters): void;
104
195
  static visitListingPage(taxonomy: Array<string>, customParameters?: CustomParameters): void;
105
196
  static visitProductDetailPage(product: RNInsiderProduct, customParameters?: CustomParameters): void;
106
- static visitCartPage(products: Array<RNInsiderProduct>, customParameters?: CustomParameters): void;
197
+ static visitCartPage(products: Array<RNInsiderProduct>): void;
198
+ static visitCartPage(products: Array<RNInsiderProduct>, customParameters: CustomParameters): void;
199
+ static visitCartPage(products: Array<RNInsiderProduct>, saleID: string): void;
200
+ static visitCartPage(products: Array<RNInsiderProduct>, saleID: string, customParameters: CustomParameters): void;
107
201
  static visitWishlistPage(products: Array<RNInsiderProduct>, customParameters?: CustomParameters): void;
108
202
  static startTrackingGeofence(): void;
109
203
  static setAllowsBackgroundLocationUpdates(allowsBackgroundLocationUpdates: boolean): void;
@@ -129,12 +223,12 @@ declare module 'react-native-insider' {
129
223
  static enableInAppMessages(): void;
130
224
  /**
131
225
  * Handles deep link URLs from Insider QR codes and email links.
132
- *
226
+ *
133
227
  * This method processes incoming URLs to enable deep linking functionality
134
228
  * for features available in the Insider panel. It parses the URL and routes
135
229
  * the user to the appropriate screen or action within the app, allowing
136
230
  * seamless integration with Insider's panel-based features.
137
- *
231
+ *
138
232
  * @platform iOS only - This method is only available on iOS platform
139
233
  * @param url - The URL string to be processed from Insider QR codes or email links
140
234
  * @example
@@ -152,4 +246,4 @@ declare module 'react-native-insider' {
152
246
  export const INAPP_SEEN: string;
153
247
  export const INSIDER_ID_LISTENER: string;
154
248
  export const SESSION_STARTED: string;
155
- }
249
+ }