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.
@@ -173,11 +173,11 @@ RCT_EXPORT_METHOD(setPhoneNumber:(NSString *)value) {
173
173
  RCT_EXPORT_METHOD(handleURL:(NSString *)value) {
174
174
  @try {
175
175
  NSURL *url = [NSURL URLWithString:value];
176
-
176
+
177
177
  if (url == nil) {
178
178
  return;
179
179
  }
180
-
180
+
181
181
  [Insider handleUrl:url];
182
182
  } @catch (NSException *e) {
183
183
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
@@ -421,11 +421,13 @@ RCT_EXPORT_METHOD(itemAddedToCart:(NSDictionary *)requiredFields optionalFields:
421
421
  }
422
422
  }
423
423
 
424
- RCT_EXPORT_METHOD(itemRemovedFromCart:(NSString *)productID customParameters:(NSArray *)customParameters) {
424
+ RCT_EXPORT_METHOD(itemRemovedFromCart:(NSString *)productID saleID:(NSString *)saleID customParameters:(NSArray *)customParameters) {
425
425
  @try {
426
426
  NSDictionary<NSString *, id> *mappedCustomParameters = [RNUtils parseCustomParameters:customParameters];
427
427
 
428
- if (mappedCustomParameters.count > 0) {
428
+ if (saleID.length > 0) {
429
+ [Insider itemRemovedFromCartWithProductID:productID saleID:saleID customParameters:mappedCustomParameters];
430
+ } else if (mappedCustomParameters.count > 0) {
429
431
  [Insider itemRemovedFromCartWithProductID:productID customParameters:mappedCustomParameters];
430
432
  } else {
431
433
  [Insider itemRemovedFromCartWithProductID:productID];
@@ -504,6 +506,38 @@ RCT_EXPORT_METHOD(getMessageCenterData:(NSInteger)limit startDate:(NSString *)st
504
506
  }
505
507
  }
506
508
 
509
+ RCT_EXPORT_METHOD(getMessageCenterDataWithIdentifiers:(NSInteger)limit startDate:(NSString *)startDate endDate:(NSString *)endDate identifiers:(NSDictionary *)identifiers callback:(RCTResponseSenderBlock) callback) {
510
+ @try {
511
+ NSTimeInterval startDateEpoch = [startDate doubleValue] / 1000.0;
512
+ NSTimeInterval endDateEpoch = [endDate doubleValue] / 1000.0;
513
+ NSDate *start = [NSDate dateWithTimeIntervalSince1970:startDateEpoch];
514
+ NSDate *end = [NSDate dateWithTimeIntervalSince1970:endDateEpoch];
515
+
516
+ InsiderIdentifiers *insiderIdentifiers = [[InsiderIdentifiers alloc] init];
517
+ for (NSString *key in identifiers.allKeys) {
518
+ if ([key isEqualToString:ADD_EMAIL]) {
519
+ insiderIdentifiers.addEmail([identifiers objectForKey:key]);
520
+ } else if ([key isEqualToString:ADD_PHONE_NUMBER]) {
521
+ insiderIdentifiers.addPhoneNumber([identifiers objectForKey:key]);
522
+ } else if ([key isEqualToString:ADD_USER_ID]) {
523
+ insiderIdentifiers.addUserID([identifiers objectForKey:key]);
524
+ } else {
525
+ insiderIdentifiers.addCustomIdentifier(key, [identifiers objectForKey:key]);
526
+ }
527
+ }
528
+
529
+ [Insider getMessageCenterDataWithLimit:limit
530
+ startDate:start
531
+ endDate:end
532
+ identifiers:insiderIdentifiers
533
+ success:^(NSArray *messageCenterData) {
534
+ callback(@[messageCenterData ?: @[]]);
535
+ }];
536
+ } @catch (NSException *e) {
537
+ [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
538
+ }
539
+ }
540
+
507
541
  RCT_EXPORT_METHOD(getSmartRecommendation:(int)recommendationID locale:(NSString *)locale currency:(NSString *)currency smartRecommendation:(RCTResponseSenderBlock) smartRecommendation) {
508
542
  @try {
509
543
  [Insider getSmartRecommendationWithID:recommendationID locale:locale currency:currency smartRecommendation:^(NSDictionary *recommendation) {
@@ -635,7 +669,7 @@ RCT_EXPORT_METHOD(visitProductDetailPage:(NSDictionary *)requiredFields optional
635
669
  }
636
670
  }
637
671
 
638
- RCT_EXPORT_METHOD(visitCartPage:(NSArray *)products customParameters:(NSArray *)customParameters) {
672
+ RCT_EXPORT_METHOD(visitCartPage:(NSArray *)products saleID:(NSString *)saleID customParameters:(NSArray *)customParameters) {
639
673
  @try {
640
674
  NSMutableArray<InsiderProduct *> *mappedProducts = [NSMutableArray array];
641
675
  for (NSDictionary *productDict in products) {
@@ -648,7 +682,9 @@ RCT_EXPORT_METHOD(visitCartPage:(NSArray *)products customParameters:(NSArray *)
648
682
 
649
683
  NSDictionary<NSString *, id> *mappedCustomParameters = [RNUtils parseCustomParameters:customParameters];
650
684
 
651
- if (mappedCustomParameters.count > 0) {
685
+ if (saleID.length > 0) {
686
+ [Insider visitCartPageWithProducts:[mappedProducts copy] saleID:saleID customParameters:mappedCustomParameters];
687
+ } else if (mappedCustomParameters.count > 0) {
652
688
  [Insider visitCartPageWithProducts:[mappedProducts copy] customParameters:mappedCustomParameters];
653
689
  } else {
654
690
  [Insider visitCartPageWithProducts:[mappedProducts copy]];
@@ -839,6 +875,104 @@ RCT_EXPORT_METHOD(enableInAppMessages) {
839
875
  }
840
876
  }
841
877
 
878
+ RCT_EXPORT_METHOD(getAppCardsCampaigns:(RCTResponseSenderBlock)callback) {
879
+ @try {
880
+ [[Insider appCards] getCampaigns:^(InsiderAppCardCampaignsResponseModel *campaignResponse, NSError *error) {
881
+ if (error) {
882
+ NSDictionary *errorDetails = [RNUtils appCardsErrorToDictionary:error];
883
+ callback(@[errorDetails]);
884
+ } else {
885
+ callback(@[[NSNull null], campaignResponse.toDictionary ?: @{}]);
886
+ }
887
+ }];
888
+ } @catch (NSException *e) {
889
+ [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
890
+ callback(@[@{@"code": @"unknown", @"message": @"An unexpected error occurred."}]);
891
+ }
892
+ }
893
+
894
+ RCT_EXPORT_METHOD(markAppCardsAsRead:(NSArray<NSString *> *)appCardIds callback:(RCTResponseSenderBlock)callback) {
895
+ @try {
896
+ [[Insider appCards] markAsRead:[NSSet setWithArray:appCardIds] completion:^(NSError *error) {
897
+ if (error) {
898
+ NSDictionary *errorDetails = [RNUtils appCardsErrorToDictionary:error];
899
+ callback(@[errorDetails]);
900
+ } else {
901
+ callback(@[]);
902
+ }
903
+ }];
904
+ } @catch (NSException *e) {
905
+ [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
906
+ callback(@[@{@"code": @"unknown", @"message": @"An unexpected error occurred."}]);
907
+ }
908
+ }
909
+
910
+ RCT_EXPORT_METHOD(markAppCardsAsUnread:(NSArray<NSString *> *)appCardIds callback:(RCTResponseSenderBlock)callback) {
911
+ @try {
912
+ [[Insider appCards] markAsUnread:[NSSet setWithArray:appCardIds] completion:^(NSError *error) {
913
+ if (error) {
914
+ NSDictionary *errorDetails = [RNUtils appCardsErrorToDictionary:error];
915
+ callback(@[errorDetails]);
916
+ } else {
917
+ callback(@[]);
918
+ }
919
+ }];
920
+ } @catch (NSException *e) {
921
+ [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
922
+ callback(@[@{@"code": @"unknown", @"message": @"An unexpected error occurred."}]);
923
+ }
924
+ }
925
+
926
+ RCT_EXPORT_METHOD(deleteAppCards:(NSArray<NSString *> *)appCardIds callback:(RCTResponseSenderBlock)callback) {
927
+ @try {
928
+ [[Insider appCards] deleteAppCards:[NSSet setWithArray:appCardIds] completion:^(NSError *error) {
929
+ if (error) {
930
+ NSDictionary *errorDetails = [RNUtils appCardsErrorToDictionary:error];
931
+ callback(@[errorDetails]);
932
+ } else {
933
+ callback(@[]);
934
+ }
935
+ }];
936
+ } @catch (NSException *e) {
937
+ [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
938
+ callback(@[@{@"code": @"unknown", @"message": @"An unexpected error occurred."}]);
939
+ }
940
+ }
941
+
942
+ RCT_EXPORT_METHOD(clickAppCardButton:(NSString *)appCardId data:(NSDictionary *)data) {
943
+ @try {
944
+ InsiderAppCardButtonModel *model = [[InsiderAppCardButtonModel alloc] initWithDictionary:data error:nil];
945
+ if (model) {
946
+ [model setAppCardId:appCardId];
947
+ [model click];
948
+ }
949
+ } @catch (NSException *e) {
950
+ [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
951
+ }
952
+ }
953
+
954
+ RCT_EXPORT_METHOD(viewAppCard:(NSDictionary *)data) {
955
+ @try {
956
+ InsiderAppCardModel *model = [[InsiderAppCardModel alloc] initWithDictionary:data error:nil];
957
+ if (model) {
958
+ [model view];
959
+ }
960
+ } @catch (NSException *e) {
961
+ [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
962
+ }
963
+ }
964
+
965
+ RCT_EXPORT_METHOD(clickAppCard:(NSDictionary *)data) {
966
+ @try {
967
+ InsiderAppCardModel *model = [[InsiderAppCardModel alloc] initWithDictionary:data error:nil];
968
+ if (model) {
969
+ [model click];
970
+ }
971
+ } @catch (NSException *e) {
972
+ [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
973
+ }
974
+ }
975
+
842
976
  -(void)insiderIDChangeListener:(NSString *) insiderID {
843
977
  @try {
844
978
  if (insiderID == nil) return;
@@ -25,4 +25,7 @@
25
25
 
26
26
  + (nonnull NSDictionary<NSString *, id> *)parseCustomParameters:(nonnull NSArray *)customParameters;
27
27
 
28
+ + (nonnull NSString *)mapAppCardsErrorCode:(nonnull NSError *)error;
29
+ + (nonnull NSDictionary *)appCardsErrorToDictionary:(nonnull NSError *)error;
30
+
28
31
  @end
@@ -283,4 +283,24 @@
283
283
  return mappedCustomParameters;
284
284
  }
285
285
 
286
+ + (NSString *)mapAppCardsErrorCode:(NSError *)error {
287
+ if ([error.domain isEqualToString:InsiderAppCardsErrorDomain]) {
288
+ switch (error.code) {
289
+ case InsiderAppCardsErrorCodeSdkNotInitialized: return @"sdkNotInitialized";
290
+ case InsiderAppCardsErrorCodeInvalidParameter: return @"invalidParameter";
291
+ case InsiderAppCardsErrorCodeNetworkError: return @"networkError";
292
+ case InsiderAppCardsErrorCodeServerError: return @"serverError";
293
+ case InsiderAppCardsErrorCodeParseError: return @"parseError";
294
+ default: return @"unknown";
295
+ }
296
+ }
297
+ return @"unknown";
298
+ }
299
+
300
+ + (NSDictionary *)appCardsErrorToDictionary:(NSError *)error {
301
+ NSString *code = [self mapAppCardsErrorCode:error];
302
+ NSString *message = error.localizedDescription ?: @"An unexpected error occurred.";
303
+ return @{@"code": code, @"message": message};
304
+ }
305
+
286
306
  @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-insider",
3
- "version": "7.1.0",
3
+ "version": "8.0.0",
4
4
  "description": "React Native Insider SDK",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -35,4 +35,4 @@
35
35
  "<rootDir>/lib/"
36
36
  ]
37
37
  }
38
- }
38
+ }
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Represents the textual content of an app card.
3
+ *
4
+ * This model contains the title and description text that is displayed in the app card.
5
+ */
6
+ export class InsiderAppCardContent {
7
+ /** Main title text of the app card. */
8
+ readonly title: string;
9
+
10
+ /** Description text of the app card. */
11
+ readonly description: string;
12
+ }
13
+
14
+ /**
15
+ * Represents an image associated with an app card.
16
+ *
17
+ * This model contains the image URL to be displayed in the app card.
18
+ */
19
+ export class InsiderAppCardImage {
20
+ /** URL of the image to be displayed. */
21
+ readonly url: string;
22
+ }
23
+
24
+ /**
25
+ * Represents an action button within an app card.
26
+ *
27
+ * This model defines a button that can be displayed in an app card, containing text and an
28
+ * associated action that is executed when the button is tapped.
29
+ */
30
+ export class InsiderAppCardButton {
31
+ /** Unique identifier for the button. */
32
+ readonly buttonId: string;
33
+
34
+ /** Identifier of the app card this button belongs to. */
35
+ readonly appCardId: string;
36
+
37
+ /** Display text shown on the button. */
38
+ readonly text: string;
39
+
40
+ /** Action to be executed when the button is tapped. */
41
+ readonly action?: InsiderAppCardAction;
42
+
43
+ /** Handles the button click action. */
44
+ click(): void;
45
+ }
46
+
47
+ /**
48
+ * Action type values for app card actions.
49
+ *
50
+ * - `"deep_link"`: deeplink navigation
51
+ * - `"open_settings"`: open system app settings
52
+ * - `"feedback"`: feedback action
53
+ */
54
+ export type InsiderAppCardActionType = "deep_link" | "open_settings" | "feedback"
55
+
56
+ /**
57
+ * Defines the interface for app card actions.
58
+ *
59
+ * Conforming types represent different actions that can be executed when a user interacts
60
+ * with an app card or button, such as opening a deeplink or navigating to app settings.
61
+ */
62
+ export class InsiderAppCardAction {
63
+ /** Type of the action (deeplink, open settings, or feedback). */
64
+ readonly type: InsiderAppCardActionType;
65
+ }
66
+
67
+ /**
68
+ * Deeplink type values.
69
+ *
70
+ * - `"external"`: external URL
71
+ * - `"internal"`: internal app navigation
72
+ * - `"url_scheme"`: URL scheme
73
+ * - `"unknown"`: unknown type
74
+ */
75
+ export type InsiderAppCardDeeplinkType = "external" | "internal" | "url_scheme" | "unknown"
76
+
77
+ /**
78
+ * Represents a deeplink action that navigates to a specific location in the app or external URL.
79
+ *
80
+ * This action model contains the data needed to construct and execute a deeplink navigation,
81
+ * including key-value pairs that define the deeplink parameters.
82
+ */
83
+ export class InsiderAppCardDeeplinkAction extends InsiderAppCardAction {
84
+ /** Key-value data containing deeplink related parameters. */
85
+ readonly keysAndValues: { key: string; value: string }[];
86
+
87
+ /** The deeplink type. */
88
+ readonly deeplinkType: InsiderAppCardDeeplinkType;
89
+
90
+ /** The deeplink URL. */
91
+ readonly url: string | null;
92
+
93
+ /** The parsed JSON data, or null if not available. */
94
+ readonly json: any | null;
95
+ }
96
+
97
+ /**
98
+ * Represents an action that opens the app's settings.
99
+ */
100
+ export class InsiderAppCardOpenSettingsAction extends InsiderAppCardAction {
101
+ }
102
+
103
+ /**
104
+ * Represents a feedback action.
105
+ */
106
+ export class InsiderAppCardFeedbackAction extends InsiderAppCardAction {
107
+ }
108
+
109
+ /**
110
+ * App card type values.
111
+ *
112
+ * - `"message"`: text-based app card
113
+ * - `"image"`: image-based app card
114
+ */
115
+ export type InsiderAppCardType = "message" | "image"
116
+
117
+ /**
118
+ * Represents a single app card.
119
+ *
120
+ * This model contains all the data for an app card, including its content,
121
+ * images, buttons, and associated actions. App cards can be either text-based or image-based.
122
+ */
123
+ export class InsiderAppCard {
124
+ /** Unique identifier for the app card. */
125
+ readonly appCardId: string;
126
+
127
+ /** Type of the app card (text or image). */
128
+ readonly type: InsiderAppCardType;
129
+
130
+ /** Flag indicating whether the app card has been read by the user. */
131
+ readonly isRead: boolean;
132
+
133
+ /** Array of images associated with the app card. */
134
+ readonly images?: InsiderAppCardImage[];
135
+
136
+ /** Content model containing the title and description of the app card. */
137
+ readonly content?: InsiderAppCardContent;
138
+
139
+ /** Array of action buttons that can be displayed with the app card. */
140
+ readonly buttons?: InsiderAppCardButton[];
141
+
142
+ /**
143
+ * Action to be executed when the app card is tapped.
144
+ */
145
+ readonly action?: InsiderAppCardAction;
146
+
147
+
148
+ /** Marks the app card as read. */
149
+ markAsRead(completion: (error?: Error) => void): void;
150
+
151
+ /** Marks the app card as read and returns a promise. */
152
+ markAsRead(): Promise<void>;
153
+
154
+ /** Marks the app card as unread. */
155
+ markAsUnread(completion: (error?: Error) => void): void;
156
+
157
+ /** Marks the app card as unread and returns a promise. */
158
+ markAsUnread(): Promise<void>;
159
+
160
+ /** Deletes the app card. */
161
+ delete(completion: (error?: Error) => void): void;
162
+
163
+ /** Deletes the app card and returns a promise. */
164
+ delete(): Promise<void>;
165
+
166
+ /** Views the app card. */
167
+ view(): void;
168
+
169
+ /** Handles the app card click action. */
170
+ click(): void;
171
+ }
172
+
173
+ /**
174
+ * Represents the campaign response containing all app cards.
175
+ *
176
+ * This model is the root container for app cards data, holding an array of app card models
177
+ * that can be displayed in the app cards UI.
178
+ */
179
+ export class InsiderAppCardsCampaignResponse {
180
+ /**
181
+ * Array of app cards.
182
+ *
183
+ * Contains all app cards retrieved from the campaigns, including both read and unread app cards.
184
+ */
185
+ readonly appCards: InsiderAppCard[];
186
+ }