react-native-nami-sdk 3.0.9 → 3.0.11

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 (43) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.js +12 -0
  3. package/.github/workflows/CI.yaml +610 -0
  4. package/.github/workflows/app_prod.yaml +316 -0
  5. package/.github/workflows/app_stg.yaml +115 -2
  6. package/.pre-commit-config.yaml +0 -1
  7. package/android/build.gradle +4 -4
  8. package/android/src/main/java/com/nami/reactlibrary/NamiBridgeModule.kt +5 -18
  9. package/android/src/main/java/com/nami/reactlibrary/NamiBridgePackage.java +0 -1
  10. package/android/src/main/java/com/nami/reactlibrary/NamiCampaignManagerBridge.kt +45 -27
  11. package/android/src/main/java/com/nami/reactlibrary/NamiCustomerManagerBridge.kt +26 -20
  12. package/android/src/main/java/com/nami/reactlibrary/NamiEntitlementManagerBridgeModule.kt +15 -12
  13. package/android/src/main/java/com/nami/reactlibrary/NamiMLManagerBridgeModule.kt +8 -0
  14. package/android/src/main/java/com/nami/reactlibrary/NamiPaywallManagerBridgeModule.kt +142 -95
  15. package/android/src/main/java/com/nami/reactlibrary/NamiPurchaseManagerBridge.kt +12 -14
  16. package/android/src/main/java/com/nami/reactlibrary/NamiUtil.kt +3 -47
  17. package/ios/Nami.m +3 -25
  18. package/ios/NamiCampaignManagerBridge.swift +13 -7
  19. package/ios/NamiCustomerManager.swift +26 -7
  20. package/ios/NamiEntitlementManagerBridge.swift +9 -1
  21. package/ios/NamiMLManagerBridge.m +0 -2
  22. package/ios/NamiPaywallManagerBridge.m +2 -59
  23. package/ios/NamiPaywallManagerBridge.swift +67 -58
  24. package/ios/NamiPurchaseManagerBridge.m +2 -98
  25. package/ios/NamiPurchaseManagerBridge.swift +45 -5
  26. package/ios/RNNami-Bridging-Header.h +0 -1
  27. package/ios/RNNami.xcodeproj/project.pbxproj +1 -62
  28. package/ios/RNNami.xcworkspace/contents.xcworkspacedata +0 -3
  29. package/package.json +15 -4
  30. package/react-native-nami-sdk.podspec +4 -2
  31. package/src/Nami.d.ts +0 -1
  32. package/src/NamiCustomerManager.js +2 -2
  33. package/src/NamiMLManager.d.ts +3 -3
  34. package/src/NamiMLManager.js +1 -1
  35. package/src/NamiPaywallManager.d.ts +11 -30
  36. package/src/NamiPaywallManager.js +13 -8
  37. package/src/NamiPurchaseManager.d.ts +7 -3
  38. package/src/types.ts +10 -3
  39. package/android/src/main/java/com/nami/reactlibrary/NamiEmitter.kt +0 -163
  40. package/ios/NamiBridgeUtil.h +0 -32
  41. package/ios/NamiBridgeUtil.m +0 -231
  42. package/ios/NamiEmitter.m +0 -350
  43. package/ios/Podfile +0 -71
package/ios/NamiEmitter.m DELETED
@@ -1,350 +0,0 @@
1
- //
2
- // NamiEmitter.m
3
- // namiReactNative
4
- //
5
- // Copyright © 2019 Nami ML Inc. All rights reserved.
6
- //
7
-
8
- #import <Foundation/Foundation.h>
9
-
10
- #import <NamiApple/NamiApple.h>
11
-
12
- #import <React/RCTBridgeModule.h>
13
- #import <React/RCTEventEmitter.h>
14
-
15
- #import "React/RCTViewManager.h"
16
- #import <UIKit/UIKit.h>
17
-
18
- #import "NamiBridgeUtil.h"
19
-
20
- @interface RCT_EXTERN_MODULE(NamiEmitter, RCTEventEmitter)
21
- RCT_EXTERN_METHOD(allPurchasedProducts)
22
- RCT_EXTERN_METHOD(getPurchasedProducts: (RCTResponseSenderBlock)callback)
23
- @end
24
-
25
- static NamiEmitter *namiEmitter;
26
-
27
- @implementation NamiEmitter : RCTEventEmitter
28
-
29
- - (instancetype)init
30
- {
31
- self = [super init];
32
- if (self) {
33
- hasNamiEmitterListeners = NO;
34
-
35
- // Tell Nami to listen for purchases and we'll forward them on to listeners
36
- [NamiPurchaseManager registerPurchasesChangedHandler:^(NSArray<NamiPurchase *> * _Nonnull purchases, enum NamiPurchaseState purchaseState, NSError * _Nullable error) {
37
- [self sendEventPurchaseMadeWithPurchases:purchases withState:purchaseState error:error];
38
- }];
39
-
40
- [NamiEntitlementManager registerActiveEntitlementsHandler:^(NSArray<NamiEntitlement *> * _Nonnull entitlements) {
41
- [self sendEventEntitlementsChangedWithEntitlements:entitlements];
42
- }];
43
-
44
- [NamiPaywallManager registerSignInHandler:^(UIViewController * _Nullable fromVC) {
45
- [self sendSignInActivateFromVC:fromVC];
46
- }];
47
-
48
- // [NamiPaywallManager registerCloseHandler:^(UIViewController * _Nullable fromVC) {
49
- // [self sendBlockingPaywallClosed];
50
- // }];
51
-
52
- [NamiPurchaseManager registerRestorePurchasesHandlerWithRestorePurchasesStateHandler:^(enum NamiRestorePurchasesState state, NSArray<NamiPurchase *> * _Nonnull newPurchases, NSArray<NamiPurchase *> * _Nonnull oldPurchases, NSError * _Nullable error) {
53
- [self sendRestorePurchasesStateChanged:state newPurchases:newPurchases oldPurchases:oldPurchases error:error];
54
- }];
55
-
56
- [NamiCustomerManager registerJourneyStateHandler:^(CustomerJourneyState * _Nonnull journeyState) {
57
- [self sendEventCustomerJourneyStateChanged:journeyState];
58
- }];
59
- }
60
- namiEmitter = self;
61
- return self;
62
- }
63
-
64
- - (void)dealloc {
65
- namiEmitter = nil;
66
- }
67
-
68
-
69
- + (NamiEmitter *) reactInstance {
70
- return namiEmitter;
71
- }
72
-
73
- - (void) getPurchasedProducts : (RCTResponseSenderBlock) callback {
74
- NSArray *allProducts = [self allPurchasedProducts];
75
- callback(allProducts);
76
- }
77
-
78
- - (NSArray<NSString *> *)allPurchasedProducts {
79
- NSArray<NamiPurchase *> *purchases = NamiPurchaseManager.allPurchases;
80
- NSMutableArray<NSString *> *productIDs = [NSMutableArray new];
81
- for (NamiPurchase *purchase in purchases) {
82
- [productIDs addObject:purchase.skuId];
83
- }
84
-
85
- return productIDs;
86
- }
87
-
88
- + (BOOL)requiresMainQueueSetup {
89
- return YES;
90
- }
91
-
92
- - (NSArray<NSString *> *)supportedEvents {
93
- return @[@"PurchasesChanged", @"SignInActivate", @"AppPaywallActivate", @"EntitlementsChanged", @"BlockingPaywallClosed", @"PreparePaywallFinished", @"RestorePurchasesStateChanged", @"CustomerJourneyStateChanged" ];
94
- }
95
-
96
- - (NSDictionary<NSString *, NSObject *> *)constantsToExport {
97
- return @{@"initialPurchasedProducts" : [self allPurchasedProducts]};
98
- }
99
-
100
- bool hasNamiEmitterListeners;
101
-
102
- // Will be called when this module's first listener is added.
103
- -(void)startObserving {
104
- hasNamiEmitterListeners = YES;
105
- }
106
-
107
- // Will be called when this module's last listener is removed, or on dealloc.
108
- -(void)stopObserving {
109
- hasNamiEmitterListeners = NO;
110
- }
111
-
112
- -(NSString *)purchaseStateToString:(NamiPurchaseState)purchaseState {
113
- switch (purchaseState) {
114
-
115
- case NamiPurchaseStatePending:
116
- return @"PENDING";
117
- break;
118
- case NamiPurchaseStatePurchased:
119
- return @"PURCHASED";
120
- break;
121
- case NamiPurchaseStateConsumed:
122
- return @"CONSUMED";
123
- break;
124
- case NamiPurchaseStateResubscribed:
125
- return @"RESUBSCRIBED";
126
- break;
127
- case NamiPurchaseStateUnsubscribed:
128
- return @"UNSUBSCRIBED";
129
- break;
130
- case NamiPurchaseStateDeferred:
131
- return @"DEFERRED";
132
- break;
133
- case NamiPurchaseStateFailed:
134
- return @"FAILED";
135
- break;
136
- case NamiPurchaseStateCancelled:
137
- return @"CANCELLED";
138
- break;
139
- case NamiPurchaseStateUnknown:
140
- return @"UNKNOWN";
141
- break;
142
- default:
143
- return @"UNKNOWN";
144
- break;
145
- }
146
- }
147
-
148
- - (void)sendEventEntitlementsChangedWithEntitlements:(NSArray<NamiEntitlement *>*)entitlements {
149
- if (hasNamiEmitterListeners) {
150
-
151
- NSMutableArray *convertedEntitlementDicts = [NSMutableArray new];
152
- for ( NamiEntitlement *entitlementRecord in entitlements ) {
153
- if ( entitlementRecord.referenceId != nil ) {
154
- NSDictionary *entitlementDict = [NamiBridgeUtil entitlementToEntitlementDict:entitlementRecord];
155
- [convertedEntitlementDicts addObject:entitlementDict];
156
- }
157
- }
158
-
159
- NSMutableDictionary *sendDict = [NSMutableDictionary dictionary];
160
- sendDict[@"activeEntitlements"] = convertedEntitlementDicts;
161
-
162
- [self sendEventWithName:@"EntitlementsChanged" body:sendDict];
163
- }
164
- }
165
-
166
- - (void)sendEventPreparePaywallForDisplayFinishedWithResult:(BOOL)success developerPaywallID: (NSString * _Nullable) developerPaywallID error:(NSError * _Nullable) error {
167
- if (hasNamiEmitterListeners) {
168
-
169
- NSMutableDictionary *sendDict = [NSMutableDictionary dictionaryWithDictionary: @{ @"success": @(success) }];
170
-
171
- if (developerPaywallID != nil) {
172
- [sendDict addEntriesFromDictionary:@{
173
- @"developerPaywallID": developerPaywallID
174
- }];
175
- }
176
-
177
- if (error != nil) {
178
- [sendDict addEntriesFromDictionary:@{
179
- @"errorCode": @(error.code),
180
- @"errorMessage": [error localizedDescription]
181
- }
182
- ];
183
- }
184
-
185
- NSLog(@"NamiBridge: Info: attempting to send result of preparePaywallForDisplay with result dictionary: %@", sendDict);
186
- [self sendEventWithName:@"PreparePaywallFinished" body:sendDict];
187
- }
188
- }
189
-
190
- - (void)sendEventCustomerJourneyStateChanged:(CustomerJourneyState *)journeyState {
191
- if (hasNamiEmitterListeners) {
192
- NSDictionary *sendDict = [NamiBridgeUtil customerJourneyStateDict];
193
- [self sendEventWithName:@"CustomerJourneyStateChanged" body:sendDict];
194
- }
195
- }
196
-
197
- - (void)sendEventPurchaseMadeWithPurchases:(NSArray<NamiPurchase *>*)purchases withState:(NamiPurchaseState)purchaseState error:(NSError *)error {
198
- if (hasNamiEmitterListeners) {
199
-
200
-
201
- NSString *convertedState = [self purchaseStateToString:purchaseState];
202
-
203
- NSMutableArray *convertedPurchaseDicts = [NSMutableArray new];
204
- for ( NamiPurchase *purchaseRecord in purchases ) {
205
- if ( purchaseRecord.skuId != nil ) {
206
- NSDictionary *purchaseDict = [NamiBridgeUtil purchaseToPurchaseDict:purchaseRecord];
207
- [convertedPurchaseDicts addObject:purchaseDict];
208
- }
209
- }
210
-
211
- NSString *localizedErrorDescription = [error localizedDescription];
212
-
213
- NSMutableDictionary *sendDict = [NSMutableDictionary dictionary];
214
- sendDict[@"purchases"] = convertedPurchaseDicts;
215
- sendDict[@"purchaseState"] = convertedState;
216
- if (localizedErrorDescription != nil) {
217
- sendDict[@"error"] = localizedErrorDescription;
218
- }
219
-
220
- [self sendEventWithName:@"PurchasesChanged" body:sendDict];
221
- }
222
- }
223
-
224
-
225
- - (void) sendSignInActivateFromVC:(UIViewController * _Nullable) fromVC {
226
- if (hasNamiEmitterListeners) {
227
- // Pass along paywall ID use in sign-in provider.
228
- [self sendEventWithName:@"SignInActivate" body:@{ }];
229
- }
230
- }
231
-
232
- //- (void)sendPaywallActivatedForPaywall:(NSString * _Nonnull) developerPaywallID
233
- // withProducts:(NSArray<NamiSKU *> * _Nullable) products
234
- // paywallMetadata:(NamiPaywall * _Nonnull) paywallMetadata {
235
- // if (hasNamiEmitterListeners) {
236
- // NSMutableArray<NSDictionary<NSString *,NSString *> *> *skuDicts = [NSMutableArray new];
237
- // for (NamiSKU *sku in products) {
238
- // [skuDicts addObject:[NamiBridgeUtil skuToSKUDict:sku]];
239
- // }
240
- //
241
- // NSMutableDictionary *paywallMeta = [NSMutableDictionary dictionaryWithDictionary:paywallMetadata.namiPaywallInfoDict];
242
- // // This part is really meant to be internally facing, scrub from dictionary
243
- //
244
- // NSMutableDictionary *marketingContentDictionary = [NSMutableDictionary dictionaryWithDictionary:paywallMeta[@"marketing_content"]];
245
- //
246
- // // Populated SmartText formatted values in dictioanry to send
247
- // marketingContentDictionary[@"body"] = [paywallMetadata body];
248
- // marketingContentDictionary[@"title"] = [paywallMetadata title];
249
- // paywallMeta[@"marketing_content"] = marketingContentDictionary;
250
- // paywallMeta[@"purchase_terms"] = [paywallMetadata purchaseTerms];
251
- //
252
- // // Strip out presention_position from all listed sku items
253
- // NSArray *cleanedOrderdMetadata = [NamiBridgeUtil stripPresentationPositionFromOrderedMetadataForPaywallMetaDict:paywallMeta];
254
- // [paywallMeta setObject:cleanedOrderdMetadata forKey:@"formatted_skus"];
255
- //
256
- // [paywallMeta removeObjectForKey:@"sku_ordered_metadata"];
257
- // [paywallMeta removeObjectForKey:@"skus"];
258
- //
259
- // NSDictionary *paywallStylingDict = [NamiBridgeUtil paywallStylingToPaywallStylingDict:[paywallMetadata styleData]];
260
- // paywallMeta[@"styleData"] = paywallStylingDict;
261
- //
262
- // // remove keys that are inconsistent with android
263
- // [paywallMeta removeObjectForKey:@"body"];
264
- // [paywallMeta removeObjectForKey:@"title"];
265
- // [paywallMeta removeObjectForKey:@"style"];
266
- //
267
- // [self sendEventWithName:@"AppPaywallActivate" body:@{ @"namiSkus": skuDicts,
268
- // @"developerPaywallID": developerPaywallID,
269
- // @"paywallMetadata": paywallMeta }];
270
- // }
271
- //}
272
-
273
- - (NSDictionary *)buildRestorePurchasesStateChangedDict: (enum NamiRestorePurchasesState) state
274
- newPurchases: (NSArray<NamiPurchase *> * _Nonnull) newPurchases
275
- oldPurchases: (NSArray<NamiPurchase *> * _Nonnull) oldPurchases
276
- error: (NSError * _Nullable) error {
277
- NSString *errorDesc = [error localizedDescription];
278
- NSDictionary *initialDict;
279
- if ([errorDesc length] > 0) {
280
- initialDict = @{@"state": [NSNumber numberWithBool:state], @"stateDesc": [self restorePurchaseStateDescriptionFromCode:state], @"error": [error localizedDescription]};
281
- } else {
282
- initialDict = @{@"state": [NSNumber numberWithBool:state], @"stateDesc": [self restorePurchaseStateDescriptionFromCode:state]};
283
- }
284
-
285
- NSMutableDictionary *retDict = [NSMutableDictionary dictionary];
286
- [retDict addEntriesFromDictionary:initialDict];
287
-
288
- NSMutableArray *newPurchaseDicts = [NSMutableArray array];
289
- for ( NamiPurchase *purchaseRecord in newPurchases ) {
290
- if ( purchaseRecord.skuId == nil ) {
291
- }
292
- NSDictionary *purchaseDict = [NamiBridgeUtil purchaseToPurchaseDict:purchaseRecord];
293
- [newPurchaseDicts addObject:purchaseDict];
294
- }
295
-
296
- NSMutableArray *oldPurchaseDicts = [NSMutableArray array];
297
- for ( NamiPurchase *purchaseRecord in oldPurchases ) {
298
- if ( purchaseRecord.skuId == nil ) {
299
- }
300
- NSDictionary *purchaseDict = [NamiBridgeUtil purchaseToPurchaseDict:purchaseRecord];
301
- [oldPurchaseDicts addObject:purchaseDict];
302
- }
303
-
304
- retDict[@"newPurchases"] = newPurchaseDicts;
305
- retDict[@"oldPurchases"] = oldPurchaseDicts;
306
-
307
- NSLog(@"NamiBridge: Info: RestorePurchases state change: %@", retDict);
308
-
309
- return retDict;
310
- }
311
-
312
- - (void)sendRestorePurchasesStateChanged: (enum NamiRestorePurchasesState) state
313
- newPurchases: (NSArray<NamiPurchase *> * _Nonnull) newPurchases
314
- oldPurchases: (NSArray<NamiPurchase *> * _Nonnull) oldPurchases
315
- error: (NSError * _Nullable) error {
316
- NSDictionary * retDict = [self buildRestorePurchasesStateChangedDict:state newPurchases:newPurchases oldPurchases:oldPurchases error:error];
317
- [self sendEventWithName:@"RestorePurchasesStateChanged" body:retDict];
318
- }
319
-
320
- - (NSString *) restorePurchaseStateDescriptionFromCode:(NamiRestorePurchasesState)stateCode {
321
- switch (stateCode) {
322
- case NamiRestorePurchasesStateStarted:
323
- return @"started";
324
- break;
325
- case NamiRestorePurchasesStateFinished:
326
- return @"finished";
327
- break;
328
- case NamiRestorePurchasesStateError:
329
- return @"error";
330
- break;
331
- }
332
- }
333
-
334
- - (void) sendBlockingPaywallClosed {
335
- // Let system know a blocking paywall has been closed, in case they want to react specifically.
336
- if (hasNamiEmitterListeners) {
337
- NSMutableDictionary *paywallMeta = [NSMutableDictionary dictionary];
338
-
339
- // Strip out presention_position from all listed sku items
340
- NSArray *cleanedOrderdMetadata = [NamiBridgeUtil stripPresentationPositionFromOrderedMetadataForPaywallMetaDict:paywallMeta];
341
- [paywallMeta setObject:cleanedOrderdMetadata forKey:@"formatted_skus"];
342
-
343
- [paywallMeta removeObjectForKey:@"sku_ordered_metadata"];
344
- [paywallMeta removeObjectForKey:@"skus"];
345
-
346
- [self sendEventWithName:@"BlockingPaywallClosed" body:@{ @"blockingPaywallClosed": @true }];
347
- }
348
- }
349
-
350
- @end
package/ios/Podfile DELETED
@@ -1,71 +0,0 @@
1
-
2
- require_relative '../node_modules/react-native/scripts/react_native_pods'
3
- require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
4
-
5
- platform :ios, '14.0'
6
-
7
- source 'https://cdn.cocoapods.org/'
8
-
9
- target 'RNNami' do
10
- config = use_native_modules!
11
- pod "Nami", "3.0.9"
12
-
13
- use_react_native!(
14
- :path => config[:reactNativePath],
15
- # to enable hermes on iOS, change `false` to `true` and then install pods
16
- :hermes_enabled => false
17
- )
18
-
19
- # Enables Flipper.
20
- #
21
- # Note that if you have use_frameworks! enabled, Flipper will not work and
22
- # you should disable the next line.
23
- use_flipper!()
24
-
25
- post_install do |installer|
26
- react_native_post_install(installer)
27
- #__apply_Xcode_12_5_M1_post_install_workaround(installer)
28
-
29
- puts("Attempting to add Nami.xcframework reference to react-native-nami-sdk project.")
30
- installer.pods_project.targets.each do |target|
31
- if target.name == "Pods-RNNami"
32
- puts("Found Pods-RNNami target.")
33
- all_filerefs = installer.pods_project.files
34
- all_filerefs.each do |fileref|
35
- if fileref.path.end_with? "Nami.xcframework"
36
- puts("Found Nami.xcframework fileref.")
37
- build_phase = target.frameworks_build_phase
38
- puts("Determining if Pods-RNNami build phase needs correction.")
39
- unless build_phase.files_references.include?(fileref)
40
- puts("Adding Nami.xcframework to Pods-RNNami target")
41
- build_phase.add_file_reference(fileref)
42
- end
43
- end
44
- end
45
- end
46
- end
47
- ## Fix for XCode 12+, hotpatch of react files should be a great idea
48
- find_and_replace("../node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm",
49
- "_initializeModules:(NSArray<id<RCTBridgeModule>> *)modules", "_initializeModules:(NSArray<Class> *)modules")
50
- find_and_replace("../node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm",
51
- "RCTBridgeModuleNameForClass(module))", "RCTBridgeModuleNameForClass(Class(module)))")
52
-
53
-
54
- end
55
- end
56
-
57
-
58
-
59
-
60
- def find_and_replace(dir, findstr, replacestr)
61
- Dir[dir].each do |name|
62
- text = File.read(name)
63
- replace = text.gsub(findstr,replacestr)
64
- if text != replace
65
- puts "Fix: " + name
66
- File.open(name, "w") { |file| file.puts replace }
67
- STDOUT.flush
68
- end
69
- end
70
- Dir[dir + '*/'].each(&method(:find_and_replace))
71
- end