@encorekit/react-native 1.1.15
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 +201 -0
- package/android/build.gradle +80 -0
- package/android/gradle.properties +11 -0
- package/android/src/main/AndroidManifest.xml +9 -0
- package/android/src/main/java/com/encorereactsdk/EncoreReactSDKModule.kt +216 -0
- package/android/src/main/java/com/encorereactsdk/EncoreReactSDKPackage.kt +22 -0
- package/encore-react-sdk.podspec +24 -0
- package/ios/EncoreReactSDK-Bridging-Header.h +7 -0
- package/ios/EncoreReactSDK.m +42 -0
- package/ios/EncoreReactSDK.swift +229 -0
- package/lib/commonjs/hooks.js +38 -0
- package/lib/commonjs/hooks.js.map +1 -0
- package/lib/commonjs/index.js +87 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/hooks.js +29 -0
- package/lib/module/hooks.js.map +1 -0
- package/lib/module/index.js +69 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/src/hooks.d.ts +11 -0
- package/lib/typescript/src/hooks.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +77 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +168 -0
- package/src/hooks.tsx +38 -0
- package/src/index.ts +147 -0
package/package.json
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@encorekit/react-native",
|
|
3
|
+
"version": "1.1.15",
|
|
4
|
+
"sdkVersions": {
|
|
5
|
+
"ios": {
|
|
6
|
+
"EncoreKit": "1.4.34"
|
|
7
|
+
},
|
|
8
|
+
"android": {
|
|
9
|
+
"com.encorekit:encore": "1.4.25"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"description": "Encore React Native bridge — thin native module layer delegating to encore-swift-sdk (iOS) and encore-android-sdk (Android)",
|
|
13
|
+
"main": "lib/commonjs/index.js",
|
|
14
|
+
"module": "lib/module/index.js",
|
|
15
|
+
"types": "lib/typescript/index.d.ts",
|
|
16
|
+
"react-native": "src/index.ts",
|
|
17
|
+
"source": "src/index.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"src",
|
|
20
|
+
"lib",
|
|
21
|
+
"android",
|
|
22
|
+
"ios",
|
|
23
|
+
"cpp",
|
|
24
|
+
"*.podspec",
|
|
25
|
+
"!lib/typescript/example",
|
|
26
|
+
"!ios/build",
|
|
27
|
+
"!android/build",
|
|
28
|
+
"!android/gradle",
|
|
29
|
+
"!android/gradlew",
|
|
30
|
+
"!android/gradlew.bat",
|
|
31
|
+
"!android/local.properties",
|
|
32
|
+
"!**/__tests__",
|
|
33
|
+
"!**/__fixtures__",
|
|
34
|
+
"!**/__mocks__",
|
|
35
|
+
"!**/.*"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"test": "jest",
|
|
39
|
+
"typecheck": "tsc --noEmit",
|
|
40
|
+
"lint": "eslint \"src/**/*.{ts,tsx}\"",
|
|
41
|
+
"prepare": "bob build",
|
|
42
|
+
"release": "release-it",
|
|
43
|
+
"build": "bob build",
|
|
44
|
+
"build:all": "npm run build"
|
|
45
|
+
},
|
|
46
|
+
"keywords": [
|
|
47
|
+
"react-native",
|
|
48
|
+
"ios",
|
|
49
|
+
"android",
|
|
50
|
+
"encore",
|
|
51
|
+
"offers",
|
|
52
|
+
"sdk",
|
|
53
|
+
"monetization",
|
|
54
|
+
"entitlements"
|
|
55
|
+
],
|
|
56
|
+
"repository": {
|
|
57
|
+
"type": "git",
|
|
58
|
+
"url": "git+https://github.com/EncoreKit/react-native-sdk.git"
|
|
59
|
+
},
|
|
60
|
+
"author": "Encore <support@encorekit.com>",
|
|
61
|
+
"license": "MIT",
|
|
62
|
+
"bugs": {
|
|
63
|
+
"url": "https://github.com/EncoreKit/react-native-sdk/issues"
|
|
64
|
+
},
|
|
65
|
+
"homepage": "https://github.com/EncoreKit/react-native-sdk#readme",
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"registry": "https://registry.npmjs.org/"
|
|
68
|
+
},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"@babel/preset-env": "^7.29.0",
|
|
71
|
+
"@babel/preset-react": "^7.28.5",
|
|
72
|
+
"@babel/preset-typescript": "^7.28.5",
|
|
73
|
+
"@commitlint/config-conventional": "^17.0.2",
|
|
74
|
+
"@evilmartians/lefthook": "^1.2.2",
|
|
75
|
+
"@react-native-community/eslint-config": "^3.0.2",
|
|
76
|
+
"@release-it/conventional-changelog": "^5.0.0",
|
|
77
|
+
"@types/jest": "^28.1.2",
|
|
78
|
+
"@types/react": "~17.0.21",
|
|
79
|
+
"@types/react-native": "0.70.0",
|
|
80
|
+
"commitlint": "^17.0.2",
|
|
81
|
+
"del-cli": "^5.0.0",
|
|
82
|
+
"eslint": "^8.57.1",
|
|
83
|
+
"eslint-config-prettier": "^8.5.0",
|
|
84
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
85
|
+
"jest": "^28.1.1",
|
|
86
|
+
"pod-install": "^0.1.0",
|
|
87
|
+
"prettier": "^2.0.5",
|
|
88
|
+
"react": "18.2.0",
|
|
89
|
+
"react-native": "0.72.6",
|
|
90
|
+
"react-native-builder-bob": "^0.20.0",
|
|
91
|
+
"react-test-renderer": "^18.2.0",
|
|
92
|
+
"release-it": "^15.0.0"
|
|
93
|
+
},
|
|
94
|
+
"peerDependencies": {
|
|
95
|
+
"react": "*",
|
|
96
|
+
"react-native": "*"
|
|
97
|
+
},
|
|
98
|
+
"engines": {
|
|
99
|
+
"node": ">= 16.0.0"
|
|
100
|
+
},
|
|
101
|
+
"jest": {
|
|
102
|
+
"testEnvironment": "node",
|
|
103
|
+
"transform": {
|
|
104
|
+
"^.+\\.(ts|tsx)$": [
|
|
105
|
+
"babel-jest",
|
|
106
|
+
{
|
|
107
|
+
"presets": [
|
|
108
|
+
[
|
|
109
|
+
"@babel/preset-env",
|
|
110
|
+
{
|
|
111
|
+
"targets": {
|
|
112
|
+
"node": "current"
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"@babel/preset-typescript",
|
|
117
|
+
[
|
|
118
|
+
"@babel/preset-react",
|
|
119
|
+
{
|
|
120
|
+
"runtime": "automatic"
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
},
|
|
127
|
+
"modulePathIgnorePatterns": [
|
|
128
|
+
"<rootDir>/example/node_modules",
|
|
129
|
+
"<rootDir>/lib/"
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
"commitlint": {
|
|
133
|
+
"extends": [
|
|
134
|
+
"@commitlint/config-conventional"
|
|
135
|
+
]
|
|
136
|
+
},
|
|
137
|
+
"release-it": {
|
|
138
|
+
"git": {
|
|
139
|
+
"commitMessage": "chore: release ${version}",
|
|
140
|
+
"tagName": "v${version}"
|
|
141
|
+
},
|
|
142
|
+
"npm": {
|
|
143
|
+
"publish": true
|
|
144
|
+
},
|
|
145
|
+
"github": {
|
|
146
|
+
"release": true
|
|
147
|
+
},
|
|
148
|
+
"plugins": {
|
|
149
|
+
"@release-it/conventional-changelog": {
|
|
150
|
+
"preset": "angular"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
"react-native-builder-bob": {
|
|
155
|
+
"source": "src",
|
|
156
|
+
"output": "lib",
|
|
157
|
+
"targets": [
|
|
158
|
+
"commonjs",
|
|
159
|
+
"module",
|
|
160
|
+
[
|
|
161
|
+
"typescript",
|
|
162
|
+
{
|
|
163
|
+
"project": "tsconfig.build.json"
|
|
164
|
+
}
|
|
165
|
+
]
|
|
166
|
+
]
|
|
167
|
+
}
|
|
168
|
+
}
|
package/src/hooks.tsx
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React, { createContext, useContext, useRef } from 'react';
|
|
2
|
+
import Encore from './index';
|
|
3
|
+
import type { ConfigureOptions, EncoreSDK } from './index';
|
|
4
|
+
|
|
5
|
+
const EncoreContext = createContext<EncoreSDK | null>(null);
|
|
6
|
+
|
|
7
|
+
interface EncoreProviderProps {
|
|
8
|
+
apiKey: string;
|
|
9
|
+
options?: ConfigureOptions;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function EncoreProvider({ apiKey, options, children }: EncoreProviderProps) {
|
|
14
|
+
const initialized = useRef(false);
|
|
15
|
+
|
|
16
|
+
if (!initialized.current) {
|
|
17
|
+
initialized.current = true;
|
|
18
|
+
// Fire synchronously during render so configure() lands on the native side
|
|
19
|
+
// before any child useEffect can call identify()/show().
|
|
20
|
+
// The native configure() is synchronous — the Promise is just bridge overhead.
|
|
21
|
+
Encore.configure(apiKey, options);
|
|
22
|
+
Encore.registerCallbacks();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<EncoreContext.Provider value={Encore}>
|
|
27
|
+
{children}
|
|
28
|
+
</EncoreContext.Provider>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function useEncoreContext(): EncoreSDK {
|
|
33
|
+
const context = useContext(EncoreContext);
|
|
34
|
+
if (!context) {
|
|
35
|
+
throw new Error('useEncoreContext must be used within an EncoreProvider');
|
|
36
|
+
}
|
|
37
|
+
return context;
|
|
38
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// Encore React Native SDK
|
|
2
|
+
// Bridge-only layer — delegates to native SDKs on each platform.
|
|
3
|
+
// iOS: encore-swift-sdk | Android: encore-android-sdk
|
|
4
|
+
|
|
5
|
+
import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
|
|
6
|
+
|
|
7
|
+
const { EncoreReactSDK } = NativeModules;
|
|
8
|
+
|
|
9
|
+
if (!EncoreReactSDK) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
`EncoreReactSDK native module not found. Ensure the native ${Platform.OS} SDK is properly linked.`
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const encoreEmitter = new NativeEventEmitter(EncoreReactSDK);
|
|
16
|
+
|
|
17
|
+
async function safeBridgeCall<T>(
|
|
18
|
+
method: string,
|
|
19
|
+
call: () => Promise<T>,
|
|
20
|
+
fallback: T,
|
|
21
|
+
): Promise<T> {
|
|
22
|
+
try {
|
|
23
|
+
return await call();
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.warn(`[Encore] ${method} failed:`, error);
|
|
26
|
+
return fallback;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// -- Types --
|
|
31
|
+
|
|
32
|
+
export interface UserAttributes {
|
|
33
|
+
email?: string;
|
|
34
|
+
firstName?: string;
|
|
35
|
+
lastName?: string;
|
|
36
|
+
phoneNumber?: string;
|
|
37
|
+
postalCode?: string;
|
|
38
|
+
city?: string;
|
|
39
|
+
state?: string;
|
|
40
|
+
countryCode?: string;
|
|
41
|
+
latitude?: string;
|
|
42
|
+
longitude?: string;
|
|
43
|
+
dateOfBirth?: string;
|
|
44
|
+
gender?: string;
|
|
45
|
+
language?: string;
|
|
46
|
+
subscriptionTier?: string;
|
|
47
|
+
monthsSubscribed?: string;
|
|
48
|
+
billingCycle?: string;
|
|
49
|
+
lastPaymentAmount?: string;
|
|
50
|
+
lastActiveDate?: string;
|
|
51
|
+
totalSessions?: string;
|
|
52
|
+
custom?: Record<string, string>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ConfigureOptions {
|
|
56
|
+
logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface PlacementResult {
|
|
60
|
+
status: 'granted' | 'not_granted' | 'completed' | 'dismissed' | 'no_offers';
|
|
61
|
+
reason?: string;
|
|
62
|
+
entitlement?: string;
|
|
63
|
+
offerId?: string;
|
|
64
|
+
campaignId?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface PurchaseRequestEvent {
|
|
68
|
+
productId: string;
|
|
69
|
+
placementId?: string;
|
|
70
|
+
promoOfferId?: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface PurchaseCompleteEvent {
|
|
74
|
+
productId: string;
|
|
75
|
+
transactionId?: string;
|
|
76
|
+
purchaseToken?: string;
|
|
77
|
+
orderId?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface PassthroughEvent {
|
|
81
|
+
placementId?: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// -- SDK Interface --
|
|
85
|
+
|
|
86
|
+
export interface EncoreSDK {
|
|
87
|
+
configure(apiKey: string, options?: ConfigureOptions): Promise<{ success: boolean }>;
|
|
88
|
+
identify(userId: string, attributes?: UserAttributes): Promise<{ success: boolean }>;
|
|
89
|
+
setUserAttributes(attributes: UserAttributes): Promise<{ success: boolean }>;
|
|
90
|
+
reset(): Promise<{ success: boolean }>;
|
|
91
|
+
show(placementId: string): Promise<PlacementResult>;
|
|
92
|
+
setClaimEnabled(enabled: boolean): Promise<{ success: boolean }>;
|
|
93
|
+
registerCallbacks(): Promise<{ success: boolean }>;
|
|
94
|
+
completePurchaseRequest(success: boolean): Promise<{ success: boolean }>;
|
|
95
|
+
onPurchaseRequest(handler: (event: PurchaseRequestEvent) => void): () => void;
|
|
96
|
+
onPurchaseComplete(handler: (event: PurchaseCompleteEvent) => void): () => void;
|
|
97
|
+
onPassthrough(handler: (event: PassthroughEvent) => void): () => void;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// -- Typed Export --
|
|
101
|
+
|
|
102
|
+
const Encore: EncoreSDK = {
|
|
103
|
+
configure: (apiKey, options = {}) =>
|
|
104
|
+
safeBridgeCall('configure', () => EncoreReactSDK.configure(apiKey, options), { success: false }),
|
|
105
|
+
|
|
106
|
+
identify: (userId, attributes) =>
|
|
107
|
+
safeBridgeCall('identify', () => EncoreReactSDK.identify(userId, attributes ?? null), { success: false }),
|
|
108
|
+
|
|
109
|
+
setUserAttributes: (attributes) =>
|
|
110
|
+
safeBridgeCall('setUserAttributes', () => EncoreReactSDK.setUserAttributes(attributes), { success: false }),
|
|
111
|
+
|
|
112
|
+
reset: () =>
|
|
113
|
+
safeBridgeCall('reset', () => EncoreReactSDK.reset(), { success: false }),
|
|
114
|
+
|
|
115
|
+
show: (placementId) =>
|
|
116
|
+
safeBridgeCall('show', () => EncoreReactSDK.show(placementId), {
|
|
117
|
+
status: 'not_granted' as const,
|
|
118
|
+
reason: 'sdk_error',
|
|
119
|
+
}),
|
|
120
|
+
|
|
121
|
+
setClaimEnabled: (enabled) =>
|
|
122
|
+
safeBridgeCall('setClaimEnabled', () => EncoreReactSDK.setClaimEnabled(enabled), { success: false }),
|
|
123
|
+
|
|
124
|
+
registerCallbacks: () =>
|
|
125
|
+
safeBridgeCall('registerCallbacks', () => EncoreReactSDK.registerCallbacks(), { success: false }),
|
|
126
|
+
|
|
127
|
+
completePurchaseRequest: (success) =>
|
|
128
|
+
safeBridgeCall('completePurchaseRequest', () => EncoreReactSDK.completePurchaseRequest(success), { success: false }),
|
|
129
|
+
|
|
130
|
+
onPurchaseRequest: (handler) => {
|
|
131
|
+
const subscription = encoreEmitter.addListener('onPurchaseRequest', handler);
|
|
132
|
+
return () => subscription.remove();
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
onPurchaseComplete: (handler) => {
|
|
136
|
+
const subscription = encoreEmitter.addListener('onPurchaseComplete', handler);
|
|
137
|
+
return () => subscription.remove();
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
onPassthrough: (handler) => {
|
|
141
|
+
const subscription = encoreEmitter.addListener('onPassthrough', handler);
|
|
142
|
+
return () => subscription.remove();
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export default Encore;
|
|
147
|
+
export { EncoreProvider, useEncoreContext } from './hooks';
|