react-native-nami-sdk 3.0.24 → 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.
- package/.eslintignore +1 -1
- package/.eslintrc.js +40 -0
- package/.github/workflows/CI.yaml +242 -5
- package/.prettierrc.js +7 -0
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/nami/reactlibrary/NamiBridgeModule.kt +1 -1
- package/android/src/main/java/com/nami/reactlibrary/NamiCampaignManagerBridge.kt +23 -64
- package/android/src/main/java/com/nami/reactlibrary/NamiPaywallManagerBridgeModule.kt +1 -1
- package/android/src/main/java/com/nami/reactlibrary/NamiUtil.kt +1 -2
- package/index.d.ts +8 -20
- package/index.ts +8 -0
- package/ios/Nami.m +1 -1
- package/ios/NamiCampaignManagerBridge.swift +1 -1
- package/package.json +6 -2
- package/react-native-nami-sdk.podspec +1 -1
- package/src/Nami.ts +21 -0
- package/src/NamiCampaignManager.d.ts +2 -1
- package/src/NamiCampaignManager.ts +143 -0
- package/src/NamiCustomerManager.ts +89 -0
- package/src/NamiEntitlementManager.d.ts +5 -6
- package/src/NamiEntitlementManager.ts +58 -0
- package/src/NamiMLManager.ts +13 -0
- package/src/NamiPaywallManager.ts +141 -0
- package/src/NamiPurchaseManager.d.ts +27 -27
- package/src/NamiPurchaseManager.ts +100 -0
- package/src/types.ts +255 -13
- package/tsconfig.json +69 -0
- package/index.js +0 -7
- package/src/Nami.js +0 -10
- package/src/NamiCampaignManager.js +0 -76
- package/src/NamiCustomerManager.js +0 -35
- package/src/NamiEntitlementManager.js +0 -23
- package/src/NamiMLManager.js +0 -7
- package/src/NamiPaywallManager.js +0 -73
- package/src/NamiPurchaseManager.js +0 -37
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NativeModules,
|
|
3
|
+
NativeEventEmitter,
|
|
4
|
+
EmitterSubscription,
|
|
5
|
+
} from 'react-native';
|
|
6
|
+
import {
|
|
7
|
+
LaunchCampaignError,
|
|
8
|
+
NamiCampaign,
|
|
9
|
+
NamiPaywallAction,
|
|
10
|
+
NamiPurchase,
|
|
11
|
+
PaywallLaunchContext,
|
|
12
|
+
} from './types';
|
|
13
|
+
|
|
14
|
+
export const { RNNamiCampaignManager } = NativeModules;
|
|
15
|
+
|
|
16
|
+
export enum NamiCampaignManagerEvents {
|
|
17
|
+
ResultCampaign = 'ResultCampaign',
|
|
18
|
+
AvailableCampaignsChanged = 'AvailableCampaignsChanged',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const searchString_Nami = 'NAMI_';
|
|
22
|
+
|
|
23
|
+
interface ICampaignManager {
|
|
24
|
+
launchSubscription: EmitterSubscription | undefined;
|
|
25
|
+
emitter: NativeEventEmitter;
|
|
26
|
+
allCampaigns: () => Promise<Array<NamiCampaign>>;
|
|
27
|
+
isCampaignAvailable(campaignSource: string | null): Promise<boolean>;
|
|
28
|
+
launch: (
|
|
29
|
+
label?: string,
|
|
30
|
+
withUrl?: string,
|
|
31
|
+
context?: PaywallLaunchContext,
|
|
32
|
+
resultCallback?: (success: boolean, error?: LaunchCampaignError) => void,
|
|
33
|
+
actionCallback?: (
|
|
34
|
+
action: NamiPaywallAction,
|
|
35
|
+
campaignId: string,
|
|
36
|
+
paywallId: string,
|
|
37
|
+
campaignName?: string,
|
|
38
|
+
campaignType?: string,
|
|
39
|
+
campaignLabel?: string,
|
|
40
|
+
campaignUrl?: string,
|
|
41
|
+
paywallName?: string,
|
|
42
|
+
segmentId?: string,
|
|
43
|
+
externalSegmentId?: string,
|
|
44
|
+
deeplinkUrl?: string,
|
|
45
|
+
skuId?: string,
|
|
46
|
+
componentChangeId?: string,
|
|
47
|
+
componentChangeName?: string,
|
|
48
|
+
purchaseError?: string,
|
|
49
|
+
purchases?: NamiPurchase[],
|
|
50
|
+
) => void,
|
|
51
|
+
) => void;
|
|
52
|
+
refresh: () => void;
|
|
53
|
+
registerAvailableCampaignsHandler: (
|
|
54
|
+
callback: (availableCampaigns: NamiCampaign[]) => void,
|
|
55
|
+
) => EmitterSubscription['remove'];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const NamiCampaignManager: ICampaignManager = {
|
|
59
|
+
launchSubscription: undefined,
|
|
60
|
+
emitter: new NativeEventEmitter(RNNamiCampaignManager),
|
|
61
|
+
...RNNamiCampaignManager,
|
|
62
|
+
launch(label, withUrl, context, resultCallback, actionCallback) {
|
|
63
|
+
if (this.launchSubscription) {
|
|
64
|
+
this.launchSubscription.remove();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
this.launchSubscription = this.emitter.addListener(
|
|
68
|
+
NamiCampaignManagerEvents.ResultCampaign,
|
|
69
|
+
body => {
|
|
70
|
+
body.action = body.action.startsWith(searchString_Nami)
|
|
71
|
+
? body.action.substring(5, body.action.length)
|
|
72
|
+
: body.action;
|
|
73
|
+
|
|
74
|
+
const {
|
|
75
|
+
action,
|
|
76
|
+
campaignId,
|
|
77
|
+
paywallId,
|
|
78
|
+
campaignName,
|
|
79
|
+
campaignType,
|
|
80
|
+
campaignLabel,
|
|
81
|
+
campaignUrl,
|
|
82
|
+
paywallName,
|
|
83
|
+
segmentId,
|
|
84
|
+
externalSegmentId,
|
|
85
|
+
deeplinkUrl,
|
|
86
|
+
skuId,
|
|
87
|
+
componentChangeId,
|
|
88
|
+
componentChangeName,
|
|
89
|
+
purchaseError,
|
|
90
|
+
purchases,
|
|
91
|
+
} = body;
|
|
92
|
+
if (actionCallback) {
|
|
93
|
+
actionCallback(
|
|
94
|
+
action,
|
|
95
|
+
campaignId,
|
|
96
|
+
paywallId,
|
|
97
|
+
campaignName,
|
|
98
|
+
campaignType,
|
|
99
|
+
campaignLabel,
|
|
100
|
+
campaignUrl,
|
|
101
|
+
paywallName,
|
|
102
|
+
segmentId,
|
|
103
|
+
externalSegmentId,
|
|
104
|
+
deeplinkUrl,
|
|
105
|
+
skuId,
|
|
106
|
+
componentChangeId,
|
|
107
|
+
componentChangeName,
|
|
108
|
+
purchaseError,
|
|
109
|
+
purchases,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
);
|
|
114
|
+
RNNamiCampaignManager.launch(
|
|
115
|
+
label ?? null,
|
|
116
|
+
withUrl ?? null,
|
|
117
|
+
context ?? null,
|
|
118
|
+
resultCallback ?? (() => {}),
|
|
119
|
+
actionCallback ?? (() => {}),
|
|
120
|
+
);
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
isCampaignAvailable: campaignSource => {
|
|
124
|
+
return RNNamiCampaignManager.isCampaignAvailable(campaignSource ?? null);
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
registerAvailableCampaignsHandler(callback) {
|
|
128
|
+
if (typeof callback !== 'function') {
|
|
129
|
+
throw new Error('Expected callback to be a function.');
|
|
130
|
+
}
|
|
131
|
+
const subscription = this.emitter.addListener(
|
|
132
|
+
NamiCampaignManagerEvents.AvailableCampaignsChanged,
|
|
133
|
+
callback,
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
RNNamiCampaignManager.registerAvailableCampaignsHandler();
|
|
137
|
+
return () => {
|
|
138
|
+
if (subscription) {
|
|
139
|
+
subscription.remove();
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
};
|
|
@@ -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
|
|
2
|
-
import { NamiPurchase } from
|
|
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[
|
|
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
|
|
2
|
-
import { NamiSKU } from
|
|
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[
|
|
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[
|
|
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[
|
|
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?:
|
|
39
|
+
purchaseSource?: 'CAMPAIGN' | 'MARKETPLACE' | 'UNKNOWN';
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
export enum NamiPurchaseState {
|
|
43
|
-
PURCHASED =
|
|
44
|
-
FAILED =
|
|
45
|
-
CANCELLED =
|
|
46
|
-
PENDING =
|
|
47
|
-
UNKNOWN =
|
|
43
|
+
PURCHASED = 'PURCHASED',
|
|
44
|
+
FAILED = 'FAILED',
|
|
45
|
+
CANCELLED = 'CANCELLEDd',
|
|
46
|
+
PENDING = 'PENDING',
|
|
47
|
+
UNKNOWN = 'UNKNOWN',
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
export type NamiRestorePurchasesState =
|
|
50
|
+
export type NamiRestorePurchasesState = 'started' | 'finished' | 'error';
|
|
51
51
|
|
|
52
52
|
export type NamiPurchasesState =
|
|
53
|
-
|
|
|
54
|
-
|
|
|
55
|
-
|
|
|
56
|
-
|
|
|
57
|
-
|
|
|
58
|
-
|
|
|
59
|
-
|
|
|
60
|
-
|
|
|
61
|
-
|
|
|
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
|
+
};
|