react-native-nami-sdk 3.0.25 → 3.0.26

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.
@@ -0,0 +1,89 @@
1
+ import {
2
+ NativeModules,
3
+ NativeEventEmitter,
4
+ EmitterSubscription,
5
+ } from 'react-native';
6
+ import { AccountStateAction, CustomerJourneyState } from './types';
7
+
8
+ export const { RNNamiCustomerManager } = NativeModules;
9
+
10
+ export enum NamiCustomerManagerEvents {
11
+ JourneyStateChanged = 'JourneyStateChanged',
12
+ AccountStateChanged = 'AccountStateChanged',
13
+ }
14
+
15
+ export interface INamiCustomerManager {
16
+ emitter: NativeEventEmitter;
17
+ setCustomerAttribute: (key: string, value: string) => void;
18
+ getCustomerAttribute: (key: string) => Promise<string | undefined>;
19
+ clearCustomerAttribute: (key: string) => void;
20
+ clearAllCustomerAttributes: () => void;
21
+ journeyState: () => Promise<CustomerJourneyState | undefined>;
22
+ isLoggedIn: () => Promise<boolean>;
23
+ loggedInId: () => Promise<string | undefined>;
24
+ deviceId: () => Promise<string>;
25
+ login: (customerId: string) => void;
26
+ logout: () => void;
27
+ registerJourneyStateHandler: (
28
+ callback: (journeyState: CustomerJourneyState) => void,
29
+ ) => EmitterSubscription['remove'];
30
+ registerAccountStateHandler: (
31
+ callback: (
32
+ action: AccountStateAction,
33
+ success: boolean,
34
+ error?: number,
35
+ ) => void,
36
+ ) => EmitterSubscription['remove'];
37
+ clearCustomerDataPlatformId: () => void;
38
+ setCustomerDataPlatformId: (platformId: string) => void;
39
+ setAnonymousMode: (anonymousMode: boolean) => void;
40
+ inAnonymousMode: () => Promise<boolean>;
41
+ }
42
+
43
+ export const NamiCustomerManager: INamiCustomerManager = {
44
+ ...RNNamiCustomerManager,
45
+ emitter: new NativeEventEmitter(RNNamiCustomerManager),
46
+ login: customerId => {
47
+ RNNamiCustomerManager.login(customerId);
48
+ },
49
+ logout: () => {
50
+ RNNamiCustomerManager.logout();
51
+ },
52
+ registerJourneyStateHandler: (
53
+ callback: (journeyState: CustomerJourneyState) => void,
54
+ ) => {
55
+ const subscription = NamiCustomerManager.emitter.addListener(
56
+ NamiCustomerManagerEvents.JourneyStateChanged,
57
+ callback,
58
+ );
59
+ RNNamiCustomerManager.registerJourneyStateHandler();
60
+ return () => {
61
+ if (subscription) {
62
+ subscription.remove();
63
+ }
64
+ };
65
+ },
66
+ registerAccountStateHandler: (
67
+ callback: (
68
+ action: AccountStateAction,
69
+ success: boolean,
70
+ error?: number,
71
+ ) => void,
72
+ ) => {
73
+ const subscription = NamiCustomerManager.emitter.addListener(
74
+ NamiCustomerManagerEvents.AccountStateChanged,
75
+ (body: any) => {
76
+ const action: AccountStateAction = body.action.toLowerCase();
77
+ const error: number | undefined = body.error;
78
+ const success: boolean = body.success;
79
+ callback(action, success, error);
80
+ },
81
+ );
82
+ RNNamiCustomerManager.registerAccountStateHandler();
83
+ return () => {
84
+ if (subscription) {
85
+ subscription.remove();
86
+ }
87
+ };
88
+ },
89
+ };
@@ -1,16 +1,15 @@
1
- import { EmitterSubscription } from "react-native";
2
- import { NamiPurchase } from "./NamiPurchaseManager";
3
- import { NamiSKU } from "./types";
1
+ import { EmitterSubscription } from 'react-native';
2
+ import { NamiPurchase, NamiSKU } from './types';
4
3
 
5
4
  export const NamiEntitlementManager: {
6
5
  active: () => Promise<Array<NamiEntitlement>>;
7
6
  isEntitlementActive: (label?: string) => boolean;
8
7
  refresh: (
9
- resultCallback?: (entitlements?: NamiEntitlement[]) => void
8
+ resultCallback?: (entitlements?: NamiEntitlement[]) => void,
10
9
  ) => void;
11
10
  registerActiveEntitlementsHandler: (
12
- callback: (activeEntitlements: NamiEntitlement[]) => void
13
- ) => EmitterSubscription["remove"];
11
+ callback: (activeEntitlements: NamiEntitlement[]) => void,
12
+ ) => EmitterSubscription['remove'];
14
13
  };
15
14
 
16
15
  export type NamiEntitlement = {
@@ -0,0 +1,58 @@
1
+ import {
2
+ NativeModules,
3
+ NativeEventEmitter,
4
+ Platform,
5
+ EmitterSubscription,
6
+ } from 'react-native';
7
+ import { NamiEntitlement } from './types';
8
+
9
+ export const { RNNamiEntitlementManager } = NativeModules;
10
+
11
+ export enum NamiEntitlementManagerEvents {
12
+ EntitlementsChanged = 'EntitlementsChanged',
13
+ }
14
+
15
+ export interface INamiEntitlementManager {
16
+ emitter: NativeEventEmitter;
17
+ active: () => Promise<Array<NamiEntitlement>>;
18
+ isEntitlementActive: (label?: string) => boolean;
19
+ refresh: (
20
+ resultCallback?: (entitlements?: NamiEntitlement[]) => void,
21
+ ) => void;
22
+ registerActiveEntitlementsHandler: (
23
+ callback: (activeEntitlements: NamiEntitlement[]) => void,
24
+ ) => EmitterSubscription['remove'];
25
+ }
26
+
27
+ export const NamiEntitlementManager: INamiEntitlementManager = {
28
+ ...RNNamiEntitlementManager,
29
+ emitter: new NativeEventEmitter(RNNamiEntitlementManager),
30
+ refresh: (
31
+ resultCallback?: (
32
+ entitlements?: INamiEntitlementManager['NamiEntitlement'][],
33
+ ) => void,
34
+ ) => {
35
+ if (Platform.OS === 'android') {
36
+ RNNamiEntitlementManager.refresh(resultCallback ?? (() => {}));
37
+ } else {
38
+ RNNamiEntitlementManager.refresh();
39
+ }
40
+ },
41
+ registerActiveEntitlementsHandler: (
42
+ callback: (
43
+ activeEntitlements: INamiEntitlementManager['NamiEntitlement'][],
44
+ ) => void,
45
+ ) => {
46
+ let subscription: EmitterSubscription =
47
+ NamiEntitlementManager.emitter.addListener(
48
+ NamiEntitlementManagerEvents.EntitlementsChanged,
49
+ callback,
50
+ );
51
+ RNNamiEntitlementManager.registerActiveEntitlementsHandler();
52
+ return () => {
53
+ if (subscription) {
54
+ subscription.remove();
55
+ }
56
+ };
57
+ },
58
+ };
@@ -0,0 +1,13 @@
1
+ import { NativeModules } from 'react-native';
2
+
3
+ export const { NamiMLManagerBridge } = NativeModules;
4
+
5
+ export interface INamiMLManager {
6
+ coreAction: (label: string) => void;
7
+ enterCoreContent: (label: string | string[]) => void;
8
+ exitCoreContent: (label: string | string[]) => void;
9
+ }
10
+
11
+ export const NamiMLManager: INamiMLManager = {
12
+ ...NamiMLManagerBridge,
13
+ };
@@ -0,0 +1,141 @@
1
+ import {
2
+ NativeModules,
3
+ NativeEventEmitter,
4
+ EmitterSubscription,
5
+ } from 'react-native';
6
+ import {
7
+ NamiPurchaseSuccessAmazon,
8
+ NamiPurchaseSuccessApple,
9
+ NamiPurchaseSuccessGooglePlay,
10
+ NamiSKU,
11
+ } from './types';
12
+
13
+ export enum NamiPaywallManagerEvents {
14
+ RegisterBuySKU = 'RegisterBuySKU',
15
+ PaywallCloseRequested = 'PaywallCloseRequested',
16
+ PaywallSignInRequested = 'PaywallSignInRequested',
17
+ PaywallRestoreRequested = 'PaywallRestoreRequested',
18
+ }
19
+
20
+ export enum ServicesEnum {
21
+ Amazon = 'Amazon',
22
+ GooglePlay = 'GooglePlay',
23
+ }
24
+
25
+ export interface INamiPaywallManager {
26
+ paywallEmitter: NativeEventEmitter;
27
+ buySkuCompleteApple: (purchaseSuccess: NamiPurchaseSuccessApple) => void;
28
+ buySkuCompleteAmazon: (purchaseSuccess: NamiPurchaseSuccessAmazon) => void;
29
+ buySkuCompleteGooglePlay: (
30
+ purchaseSuccess: NamiPurchaseSuccessGooglePlay,
31
+ ) => void;
32
+ registerBuySkuHandler: (
33
+ callback: (sku: NamiSKU) => void,
34
+ ) => EmitterSubscription['remove'];
35
+ registerCloseHandler: (callback: () => void) => EmitterSubscription['remove'];
36
+ registerSignInHandler: (
37
+ callback: () => void,
38
+ ) => EmitterSubscription['remove'];
39
+ registerRestoreHandler: (
40
+ callback: () => void,
41
+ ) => EmitterSubscription['remove'];
42
+ dismiss: (animated?: boolean) => void;
43
+ show: () => void;
44
+ hide: () => void;
45
+ isHidden: () => Promise<void>;
46
+ }
47
+
48
+ const { NamiPaywallManagerBridge, RNNamiPaywallManager } = NativeModules;
49
+
50
+ export const NamiPaywallManager: INamiPaywallManager = {
51
+ paywallEmitter: new NativeEventEmitter(RNNamiPaywallManager),
52
+ ...RNNamiPaywallManager,
53
+ ...NamiPaywallManagerBridge,
54
+ buySkuCompleteApple: (purchaseSuccess: NamiPurchaseSuccessApple) => {
55
+ RNNamiPaywallManager.buySkuComplete(purchaseSuccess);
56
+ },
57
+ buySkuCompleteAmazon: (purchaseSuccess: NamiPurchaseSuccessAmazon) => {
58
+ RNNamiPaywallManager.buySkuComplete(purchaseSuccess, ServicesEnum.Amazon);
59
+ },
60
+ buySkuCompleteGooglePlay: (
61
+ purchaseSuccess: NamiPurchaseSuccessGooglePlay,
62
+ ) => {
63
+ RNNamiPaywallManager.buySkuComplete(
64
+ purchaseSuccess,
65
+ ServicesEnum.GooglePlay,
66
+ );
67
+ },
68
+ registerBuySkuHandler: (callback: (sku: NamiSKU) => void) => {
69
+ let subscription;
70
+ subscription = NamiPaywallManager.paywallEmitter.addListener(
71
+ NamiPaywallManagerEvents.RegisterBuySKU,
72
+ sku => {
73
+ callback(sku);
74
+ },
75
+ );
76
+ RNNamiPaywallManager.registerBuySkuHandler();
77
+ return () => {
78
+ if (subscription) {
79
+ subscription.remove();
80
+ }
81
+ };
82
+ },
83
+ registerCloseHandler: (callback: (body: any) => void) => {
84
+ let subscription;
85
+ subscription = NamiPaywallManager.paywallEmitter.addListener(
86
+ NamiPaywallManagerEvents.PaywallCloseRequested,
87
+ body => {
88
+ callback(body);
89
+ },
90
+ );
91
+ RNNamiPaywallManager.registerCloseHandler();
92
+ return () => {
93
+ if (subscription) {
94
+ subscription.remove();
95
+ }
96
+ };
97
+ },
98
+ registerSignInHandler(callback) {
99
+ let subscription;
100
+ subscription = NamiPaywallManager.paywallEmitter.addListener(
101
+ NamiPaywallManagerEvents.PaywallSignInRequested,
102
+ body => {
103
+ callback(body);
104
+ },
105
+ );
106
+ RNNamiPaywallManager.registerSignInHandler();
107
+
108
+ return () => {
109
+ if (subscription) {
110
+ subscription.remove();
111
+ }
112
+ };
113
+ },
114
+ registerRestoreHandler(callback) {
115
+ let subscription;
116
+ subscription = NamiPaywallManager.paywallEmitter.addListener(
117
+ NamiPaywallManagerEvents.PaywallRestoreRequested,
118
+ body => {
119
+ callback(body);
120
+ },
121
+ );
122
+ RNNamiPaywallManager.registerRestoreHandler();
123
+ return () => {
124
+ if (subscription) {
125
+ subscription.remove();
126
+ }
127
+ };
128
+ },
129
+ dismiss: (animated?: boolean) => {
130
+ RNNamiPaywallManager.dismiss(animated ?? true);
131
+ },
132
+ show: () => {
133
+ RNNamiPaywallManager.show();
134
+ },
135
+ hide: () => {
136
+ RNNamiPaywallManager.hide();
137
+ },
138
+ isHidden: () => {
139
+ return RNNamiPaywallManager.isHidden();
140
+ },
141
+ };
@@ -1,5 +1,5 @@
1
- import { EmitterSubscription } from "react-native";
2
- import { NamiSKU } from "./types";
1
+ import { EmitterSubscription } from 'react-native';
2
+ import { NamiSKU } from './types';
3
3
 
4
4
  export const NamiPurchaseManager: {
5
5
  allPurchases: () => NamiPurchase[];
@@ -10,24 +10,24 @@ export const NamiPurchaseManager: {
10
10
  callback: (
11
11
  purchaseState: NamiPurchasesState,
12
12
  purchases: NamiPurchase[],
13
- error: string
14
- ) => void
15
- ) => EmitterSubscription["remove"];
13
+ error: string,
14
+ ) => void,
15
+ ) => EmitterSubscription['remove'];
16
16
  skuPurchased: (skuId: string) => boolean;
17
17
  registerPurchasesChangedHandler: (
18
18
  callback: (
19
19
  purchaseState: NamiPurchasesState,
20
20
  purchases: NamiPurchase[],
21
- error: string
22
- ) => void
23
- ) => EmitterSubscription["remove"];
21
+ error: string,
22
+ ) => void,
23
+ ) => EmitterSubscription['remove'];
24
24
  registerRestorePurchasesHandler: (
25
25
  callback: (
26
26
  state: NamiRestorePurchasesState,
27
27
  newPurchases: NamiPurchase[],
28
- oldPurchases: NamiPurchase[]
29
- ) => void
30
- ) => EmitterSubscription["remove"];
28
+ oldPurchases: NamiPurchase[],
29
+ ) => void,
30
+ ) => EmitterSubscription['remove'];
31
31
  };
32
32
 
33
33
  export type NamiPurchase = {
@@ -36,26 +36,26 @@ export type NamiPurchase = {
36
36
  transactionIdentifier?: string;
37
37
  expires?: Date;
38
38
  purchaseInitiatedTimestamp: Date;
39
- purchaseSource?: "CAMPAIGN" | "MARKETPLACE" | "UNKNOWN";
39
+ purchaseSource?: 'CAMPAIGN' | 'MARKETPLACE' | 'UNKNOWN';
40
40
  };
41
41
 
42
42
  export enum NamiPurchaseState {
43
- PURCHASED = "PURCHASED",
44
- FAILED = "FAILED",
45
- CANCELLED = "CANCELLEDd",
46
- PENDING = "PENDING",
47
- UNKNOWN = "UNKNOWN",
43
+ PURCHASED = 'PURCHASED',
44
+ FAILED = 'FAILED',
45
+ CANCELLED = 'CANCELLEDd',
46
+ PENDING = 'PENDING',
47
+ UNKNOWN = 'UNKNOWN',
48
48
  }
49
49
 
50
- export type NamiRestorePurchasesState = "started" | "finished" | "error";
50
+ export type NamiRestorePurchasesState = 'started' | 'finished' | 'error';
51
51
 
52
52
  export type NamiPurchasesState =
53
- | "pending"
54
- | "purchased"
55
- | "consumed"
56
- | "resubscribed"
57
- | "unsubscribed"
58
- | "deferred"
59
- | "failed"
60
- | "cancelled"
61
- | "unknown";
53
+ | 'pending'
54
+ | 'purchased'
55
+ | 'consumed'
56
+ | 'resubscribed'
57
+ | 'unsubscribed'
58
+ | 'deferred'
59
+ | 'failed'
60
+ | 'cancelled'
61
+ | 'unknown';
@@ -0,0 +1,100 @@
1
+ import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
2
+ import { EmitterSubscription } from 'react-native';
3
+ import {
4
+ NamiPurchase,
5
+ NamiPurchasesState,
6
+ NamiRestorePurchasesState,
7
+ } from './types';
8
+
9
+ export const { NamiPurchaseManagerBridge, RNNamiPurchaseManager } =
10
+ NativeModules;
11
+
12
+ export enum NamiPurchaseManagerEvents {
13
+ PurchasesChanged = 'PurchasesChanged',
14
+ RestorePurchasesStateChanged = 'RestorePurchasesStateChanged',
15
+ }
16
+
17
+ export interface INamiPurchaseManager {
18
+ emitter: NativeEventEmitter;
19
+ allPurchases: () => NamiPurchase[];
20
+ anySkuPurchased: (skuIds: string[]) => boolean;
21
+ consumePurchasedSku: (skuId: string) => void;
22
+ presentCodeRedemptionSheet: () => void;
23
+ restorePurchases: (
24
+ callback: (
25
+ purchaseState: NamiPurchasesState,
26
+ purchases: NamiPurchase[],
27
+ error: string,
28
+ ) => void,
29
+ ) => EmitterSubscription['remove'];
30
+ skuPurchased: (skuId: string) => boolean;
31
+ registerPurchasesChangedHandler: (
32
+ callback: (
33
+ purchaseState: NamiPurchasesState,
34
+ purchases: NamiPurchase[],
35
+ error: string,
36
+ ) => void,
37
+ ) => EmitterSubscription['remove'];
38
+ registerRestorePurchasesHandler: (
39
+ callback: (
40
+ state: NamiRestorePurchasesState,
41
+ newPurchases: NamiPurchase[],
42
+ oldPurchases: NamiPurchase[],
43
+ ) => void,
44
+ ) => EmitterSubscription['remove'];
45
+ }
46
+
47
+ export const NamiPurchaseManager: INamiPurchaseManager = {
48
+ emitter: new NativeEventEmitter(RNNamiPurchaseManager),
49
+ ...NamiPurchaseManagerBridge,
50
+ ...RNNamiPurchaseManager,
51
+ registerPurchasesChangedHandler: (
52
+ callback: (
53
+ purchaseState: NamiPurchasesState,
54
+ purchases: NamiPurchase[],
55
+ error: string,
56
+ ) => void,
57
+ ) => {
58
+ const subscription = NamiPurchaseManager.emitter.addListener(
59
+ NamiPurchaseManagerEvents.PurchasesChanged,
60
+ body => {
61
+ let purchases = body.purchases;
62
+ let purchaseState =
63
+ body.purchaseState.toLowerCase() as NamiPurchasesState;
64
+ let error = body.error;
65
+ callback(purchaseState, purchases, error);
66
+ },
67
+ );
68
+ RNNamiPurchaseManager.registerPurchasesChangedHandler();
69
+ return () => {
70
+ if (subscription) {
71
+ subscription.remove();
72
+ }
73
+ };
74
+ },
75
+ registerRestorePurchasesHandler: (
76
+ callback: (
77
+ state: NamiRestorePurchasesState,
78
+ newPurchases: NamiPurchase[],
79
+ oldPurchases: NamiPurchase[],
80
+ ) => void,
81
+ ) => {
82
+ if (Platform.OS === 'ios') {
83
+ const subscription = NamiPurchaseManager.emitter.addListener(
84
+ NamiPurchaseManagerEvents.RestorePurchasesStateChanged,
85
+ body => {
86
+ let state = body.state.toLowerCase() as NamiRestorePurchasesState;
87
+ let newPurchases = body.newPurchases;
88
+ let oldPurchases = body.oldPurchases;
89
+ callback(state, newPurchases, oldPurchases);
90
+ },
91
+ );
92
+ RNNamiPurchaseManager.registerRestorePurchasesHandler();
93
+ return () => {
94
+ if (subscription) {
95
+ subscription.remove();
96
+ }
97
+ };
98
+ }
99
+ },
100
+ };