@tryheliumai/paywall-sdk-react-native 0.1.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.
- package/LICENSE +20 -0
- package/PaywallSdkReactNative.podspec +28 -0
- package/README.md +224 -0
- package/android/build.gradle +88 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/paywallsdkreactnative/PaywallSdkReactNativeModule.kt +25 -0
- package/android/src/main/java/com/paywallsdkreactnative/PaywallSdkReactNativePackage.kt +17 -0
- package/ios/HeliumSwiftInterface.swift +269 -0
- package/ios/HeliumUpsellViewManager.m +17 -0
- package/ios/HeliumUpsellViewManager.swift +95 -0
- package/ios/PaywallSdkReactNative-Bridging-Header.h +2 -0
- package/ios/RCTHeliumBridge.m +35 -0
- package/lib/commonjs/index.js +37 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/native-interface.js +128 -0
- package/lib/commonjs/native-interface.js.map +1 -0
- package/lib/commonjs/purchase-handlers.js +47 -0
- package/lib/commonjs/purchase-handlers.js.map +1 -0
- package/lib/commonjs/types.js +2 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/index.js +4 -0
- package/lib/module/index.js.map +2 -0
- package/lib/module/native-interface.js +117 -0
- package/lib/module/native-interface.js.map +1 -0
- package/lib/module/purchase-handlers.js +42 -0
- package/lib/module/purchase-handlers.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +3 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/native-interface.d.ts +13 -0
- package/lib/typescript/commonjs/src/native-interface.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/purchase-handlers.d.ts +19 -0
- package/lib/typescript/commonjs/src/purchase-handlers.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types.d.ts +19 -0
- package/lib/typescript/commonjs/src/types.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/index.d.ts +3 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/lib/typescript/module/src/native-interface.d.ts +13 -0
- package/lib/typescript/module/src/native-interface.d.ts.map +1 -0
- package/lib/typescript/module/src/purchase-handlers.d.ts +19 -0
- package/lib/typescript/module/src/purchase-handlers.d.ts.map +1 -0
- package/lib/typescript/module/src/types.d.ts +19 -0
- package/lib/typescript/module/src/types.d.ts.map +1 -0
- package/package.json +188 -0
- package/src/index.ts +2 -0
- package/src/index.tsx +2 -0
- package/src/native-interface.tsx +134 -0
- package/src/purchase-handlers.ts +39 -0
- package/src/types.ts +21 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,uBAAuB,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,UAAU,CAAC;AAEpG,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACtE,gBAAgB,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACzC,oBAAoB,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;CAC5C;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACxC;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,GAAG,CAAC;CACb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACvG,YAAY,EAAE,uBAAuB,EAAE,eAAe,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { HeliumCallbacks, HeliumConfig, HeliumUpsellViewProps } from './types';
|
|
3
|
+
interface HeliumProviderProps {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
fallbackView: React.ComponentType;
|
|
6
|
+
}
|
|
7
|
+
export declare const HeliumProvider: ({ children, fallbackView: FallbackView }: HeliumProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare const initialize: (heliumCallbacks: HeliumCallbacks, config?: Partial<HeliumConfig>) => void;
|
|
9
|
+
export declare const presentUpsell: (triggerName: string) => void;
|
|
10
|
+
export declare const hideUpsell: () => void;
|
|
11
|
+
export declare const UpsellView: React.FC<HeliumUpsellViewProps>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=native-interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-interface.d.ts","sourceRoot":"","sources":["../../../../src/native-interface.tsx"],"names":[],"mappings":"AACA,OAAO,KAA+B,MAAM,OAAO,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAgBpF,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,YAAY,EAAE,KAAK,CAAC,aAAa,CAAC;CACnC;AAMD,eAAO,MAAM,cAAc,6CAA8C,mBAAmB,4CA2B3F,CAAC;AAGF,eAAO,MAAM,UAAU,oBAAqB,eAAe,WAAU,OAAO,CAAC,YAAY,CAAC,SAwDzF,CAAC;AAGF,eAAO,MAAM,aAAa,gBAAiB,MAAM,SAEhD,CAAC;AAEF,eAAO,MAAM,UAAU,YAEtB,CAAC;AAGF,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAQtD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { HeliumTransactionStatus } from './types';
|
|
2
|
+
export interface HeliumCallbacks {
|
|
3
|
+
makePurchase: (productId: string) => Promise<string>;
|
|
4
|
+
restorePurchases: () => Promise<boolean>;
|
|
5
|
+
onHeliumPaywallEvent: (event: any) => void;
|
|
6
|
+
getCustomVariableValues: () => Record<string, any>;
|
|
7
|
+
}
|
|
8
|
+
export declare class DemoHeliumCallbacks implements HeliumCallbacks {
|
|
9
|
+
private events;
|
|
10
|
+
makePurchase(productId: string): Promise<HeliumTransactionStatus>;
|
|
11
|
+
restorePurchases(): Promise<boolean>;
|
|
12
|
+
onHeliumPaywallEvent(event: any): void;
|
|
13
|
+
getCustomVariableValues: () => Record<string, any>;
|
|
14
|
+
getEventHistory(): {
|
|
15
|
+
timestamp: Date;
|
|
16
|
+
event: any;
|
|
17
|
+
}[];
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=purchase-handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"purchase-handlers.d.ts","sourceRoot":"","sources":["../../../../src/purchase-handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAEvD,MAAM,WAAW,eAAe;IAC5B,YAAY,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACrD,gBAAgB,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACzC,oBAAoB,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IAC3C,uBAAuB,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACpD;AAGD,qBAAa,mBAAoB,YAAW,eAAe;IACzD,OAAO,CAAC,MAAM,CAAyC;IAEjD,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAKjE,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAAC;IAK1C,oBAAoB,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI;IAItC,uBAAuB,QAAO,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAM/C;IAEF,eAAe;mBAxBc,IAAI;eAAS,GAAG;;CA2B9C"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type HeliumTransactionStatus = 'completed' | 'failed' | 'cancelled' | 'pending' | 'restored';
|
|
2
|
+
export interface HeliumCallbacks {
|
|
3
|
+
makePurchase: (productId: string) => Promise<HeliumTransactionStatus>;
|
|
4
|
+
restorePurchases: () => Promise<boolean>;
|
|
5
|
+
onHeliumPaywallEvent: (event: any) => void;
|
|
6
|
+
}
|
|
7
|
+
export interface HeliumConfig {
|
|
8
|
+
apiKey: string;
|
|
9
|
+
fallbackView?: number;
|
|
10
|
+
triggers?: string[];
|
|
11
|
+
customUserId?: string;
|
|
12
|
+
customAPIEndpoint?: string;
|
|
13
|
+
customUserTraits?: Record<string, any>;
|
|
14
|
+
}
|
|
15
|
+
export interface HeliumUpsellViewProps {
|
|
16
|
+
trigger: string;
|
|
17
|
+
style?: any;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,uBAAuB,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,UAAU,CAAC;AAEpG,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACtE,gBAAgB,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACzC,oBAAoB,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;CAC5C;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACxC;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,GAAG,CAAC;CACb"}
|
package/package.json
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tryheliumai/paywall-sdk-react-native",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Paywall SDK Helium",
|
|
5
|
+
"source": "./src/index.ts",
|
|
6
|
+
"main": "./lib/commonjs/index.js",
|
|
7
|
+
"module": "./lib/module/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./lib/typescript/module/src/index.d.ts",
|
|
12
|
+
"default": "./lib/module/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./lib/typescript/commonjs/src/index.d.ts",
|
|
16
|
+
"default": "./lib/commonjs/index.js"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"src",
|
|
22
|
+
"lib",
|
|
23
|
+
"android",
|
|
24
|
+
"ios",
|
|
25
|
+
"cpp",
|
|
26
|
+
"*.podspec",
|
|
27
|
+
"react-native.config.js",
|
|
28
|
+
"!ios/build",
|
|
29
|
+
"!android/build",
|
|
30
|
+
"!android/gradle",
|
|
31
|
+
"!android/gradlew",
|
|
32
|
+
"!android/gradlew.bat",
|
|
33
|
+
"!android/local.properties",
|
|
34
|
+
"!**/__tests__",
|
|
35
|
+
"!**/__fixtures__",
|
|
36
|
+
"!**/__mocks__",
|
|
37
|
+
"!**/.*"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"example": "yarn workspace paywall-sdk-react-native-example",
|
|
41
|
+
"test": "jest",
|
|
42
|
+
"typecheck": "tsc",
|
|
43
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
44
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
45
|
+
"prepare": "bob build",
|
|
46
|
+
"release": "release-it"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"react-native",
|
|
50
|
+
"ios",
|
|
51
|
+
"android"
|
|
52
|
+
],
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "git+https://github.com/cloudcaptainai/helium-react-native-sdk.git"
|
|
56
|
+
},
|
|
57
|
+
"author": "Anish Doshi <anish@tryhelium.com> (https://tryhelium.com)",
|
|
58
|
+
"license": "MIT",
|
|
59
|
+
"bugs": {
|
|
60
|
+
"url": "https://github.com/cloudcaptainai/helium-react-native-sdk/issues"
|
|
61
|
+
},
|
|
62
|
+
"homepage": "https://github.com/cloudcaptainai/helium-react-native-sdk#readme",
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"registry": "https://registry.npmjs.org/"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@commitlint/config-conventional": "^17.0.2",
|
|
68
|
+
"@evilmartians/lefthook": "^1.5.0",
|
|
69
|
+
"@react-native/eslint-config": "^0.73.1",
|
|
70
|
+
"@release-it/conventional-changelog": "^9.0.2",
|
|
71
|
+
"@types/jest": "^29.5.5",
|
|
72
|
+
"@types/react": "^18.2.44",
|
|
73
|
+
"commitlint": "^17.0.2",
|
|
74
|
+
"del-cli": "^5.1.0",
|
|
75
|
+
"eslint": "^8.51.0",
|
|
76
|
+
"eslint-config-prettier": "^9.0.0",
|
|
77
|
+
"eslint-plugin-prettier": "^5.0.1",
|
|
78
|
+
"jest": "^29.7.0",
|
|
79
|
+
"prettier": "^3.0.3",
|
|
80
|
+
"react": "18.3.1",
|
|
81
|
+
"react-native": "0.74.0",
|
|
82
|
+
"react-native-builder-bob": "^0.37.0",
|
|
83
|
+
"release-it": "^17.10.0",
|
|
84
|
+
"turbo": "^1.10.7",
|
|
85
|
+
"typescript": "^5.2.2"
|
|
86
|
+
},
|
|
87
|
+
"resolutions": {
|
|
88
|
+
"@types/react": "^18.2.44"
|
|
89
|
+
},
|
|
90
|
+
"peerDependencies": {
|
|
91
|
+
"react": "*",
|
|
92
|
+
"react-native": "*"
|
|
93
|
+
},
|
|
94
|
+
"workspaces": [
|
|
95
|
+
"example"
|
|
96
|
+
],
|
|
97
|
+
"packageManager": "yarn@3.6.1",
|
|
98
|
+
"jest": {
|
|
99
|
+
"preset": "react-native",
|
|
100
|
+
"modulePathIgnorePatterns": [
|
|
101
|
+
"<rootDir>/example/node_modules",
|
|
102
|
+
"<rootDir>/lib/"
|
|
103
|
+
]
|
|
104
|
+
},
|
|
105
|
+
"commitlint": {
|
|
106
|
+
"extends": [
|
|
107
|
+
"@commitlint/config-conventional"
|
|
108
|
+
]
|
|
109
|
+
},
|
|
110
|
+
"release-it": {
|
|
111
|
+
"git": {
|
|
112
|
+
"commitMessage": "chore: release ${version}",
|
|
113
|
+
"tagName": "v${version}"
|
|
114
|
+
},
|
|
115
|
+
"npm": {
|
|
116
|
+
"publish": true
|
|
117
|
+
},
|
|
118
|
+
"github": {
|
|
119
|
+
"release": true
|
|
120
|
+
},
|
|
121
|
+
"plugins": {
|
|
122
|
+
"@release-it/conventional-changelog": {
|
|
123
|
+
"preset": "angular"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
"eslintConfig": {
|
|
128
|
+
"root": true,
|
|
129
|
+
"extends": [
|
|
130
|
+
"@react-native",
|
|
131
|
+
"prettier"
|
|
132
|
+
],
|
|
133
|
+
"rules": {
|
|
134
|
+
"react/react-in-jsx-scope": "off",
|
|
135
|
+
"prettier/prettier": [
|
|
136
|
+
"error",
|
|
137
|
+
{
|
|
138
|
+
"quoteProps": "consistent",
|
|
139
|
+
"singleQuote": true,
|
|
140
|
+
"tabWidth": 2,
|
|
141
|
+
"trailingComma": "es5",
|
|
142
|
+
"useTabs": false
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
"eslintIgnore": [
|
|
148
|
+
"node_modules/",
|
|
149
|
+
"lib/"
|
|
150
|
+
],
|
|
151
|
+
"prettier": {
|
|
152
|
+
"quoteProps": "consistent",
|
|
153
|
+
"singleQuote": true,
|
|
154
|
+
"tabWidth": 2,
|
|
155
|
+
"trailingComma": "es5",
|
|
156
|
+
"useTabs": false
|
|
157
|
+
},
|
|
158
|
+
"react-native-builder-bob": {
|
|
159
|
+
"source": "src",
|
|
160
|
+
"output": "lib",
|
|
161
|
+
"targets": [
|
|
162
|
+
[
|
|
163
|
+
"commonjs",
|
|
164
|
+
{
|
|
165
|
+
"esm": true
|
|
166
|
+
}
|
|
167
|
+
],
|
|
168
|
+
[
|
|
169
|
+
"module",
|
|
170
|
+
{
|
|
171
|
+
"esm": true
|
|
172
|
+
}
|
|
173
|
+
],
|
|
174
|
+
[
|
|
175
|
+
"typescript",
|
|
176
|
+
{
|
|
177
|
+
"project": "tsconfig.build.json",
|
|
178
|
+
"esm": true
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
]
|
|
182
|
+
},
|
|
183
|
+
"create-react-native-library": {
|
|
184
|
+
"type": "legacy-module",
|
|
185
|
+
"languages": "kotlin-swift",
|
|
186
|
+
"version": "0.48.1"
|
|
187
|
+
}
|
|
188
|
+
}
|
package/src/index.ts
ADDED
package/src/index.tsx
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { findNodeHandle, NativeModules, View, NativeEventEmitter, requireNativeComponent } from 'react-native';
|
|
2
|
+
import React, { createRef, useEffect } from 'react';
|
|
3
|
+
import type { HeliumCallbacks, HeliumConfig, HeliumUpsellViewProps } from './types';
|
|
4
|
+
|
|
5
|
+
const { HeliumBridge } = NativeModules;
|
|
6
|
+
const heliumEventEmitter = new NativeEventEmitter(HeliumBridge);
|
|
7
|
+
|
|
8
|
+
let isProviderMounted = false;
|
|
9
|
+
|
|
10
|
+
// Move NativeHeliumUpsellView to a singleton pattern
|
|
11
|
+
let NativeHeliumUpsellView: any = null;
|
|
12
|
+
const getNativeHeliumUpsellView = () => {
|
|
13
|
+
if (!NativeHeliumUpsellView) {
|
|
14
|
+
NativeHeliumUpsellView = requireNativeComponent<HeliumUpsellViewProps>('HeliumUpsellView');
|
|
15
|
+
}
|
|
16
|
+
return NativeHeliumUpsellView;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
interface HeliumProviderProps {
|
|
20
|
+
children: React.ReactNode;
|
|
21
|
+
fallbackView: React.ComponentType;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Create a ref to store the fallback view reference
|
|
25
|
+
const fallbackRef = createRef<View>();
|
|
26
|
+
|
|
27
|
+
// Provider component to be rendered at the app root
|
|
28
|
+
export const HeliumProvider = ({ children, fallbackView: FallbackView }: HeliumProviderProps) => {
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
isProviderMounted = true;
|
|
31
|
+
return () => {
|
|
32
|
+
isProviderMounted = false;
|
|
33
|
+
};
|
|
34
|
+
}, []);
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<>
|
|
38
|
+
{/* Mount the fallback view but keep it hidden */}
|
|
39
|
+
<View
|
|
40
|
+
ref={fallbackRef}
|
|
41
|
+
style={{
|
|
42
|
+
position: 'absolute',
|
|
43
|
+
opacity: 0,
|
|
44
|
+
width: 1,
|
|
45
|
+
height: 1,
|
|
46
|
+
overflow: 'hidden'
|
|
47
|
+
}}
|
|
48
|
+
collapsable={false}
|
|
49
|
+
>
|
|
50
|
+
<FallbackView />
|
|
51
|
+
</View>
|
|
52
|
+
{children}
|
|
53
|
+
</>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Update initialize to accept config
|
|
58
|
+
export const initialize = (heliumCallbacks: HeliumCallbacks, config: Partial<HeliumConfig> = {}) => {
|
|
59
|
+
if (!isProviderMounted) {
|
|
60
|
+
throw new Error('HeliumProvider is not mounted. Please wrap your app with HeliumProvider.');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const viewTag = findNodeHandle(fallbackRef.current);
|
|
64
|
+
if (!viewTag) {
|
|
65
|
+
throw new Error('Failed to get fallback view reference. Make sure HeliumProvider is mounted with a fallback view.');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Set up purchase event listener
|
|
69
|
+
heliumEventEmitter.addListener(
|
|
70
|
+
'helium_make_purchase',
|
|
71
|
+
async (event: { productId: string; transactionId: string }) => {
|
|
72
|
+
const status = await heliumCallbacks.makePurchase(event.productId);
|
|
73
|
+
HeliumBridge.handlePurchaseResponse({
|
|
74
|
+
transactionId: event.transactionId,
|
|
75
|
+
status: status
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// Set up restore purchases event listener
|
|
81
|
+
heliumEventEmitter.addListener(
|
|
82
|
+
'helium_restore_purchases',
|
|
83
|
+
async (event: { transactionId: string }) => {
|
|
84
|
+
const success = await heliumCallbacks.restorePurchases();
|
|
85
|
+
HeliumBridge.handleRestoreResponse({
|
|
86
|
+
transactionId: event.transactionId,
|
|
87
|
+
status: success ? 'restored' : 'failed'
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// Set up paywall event listener
|
|
93
|
+
heliumEventEmitter.addListener(
|
|
94
|
+
'helium_paywall_event',
|
|
95
|
+
(event: any) => {
|
|
96
|
+
heliumCallbacks.onHeliumPaywallEvent(event);
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
// Initialize the bridge with merged config
|
|
101
|
+
HeliumBridge.initialize(
|
|
102
|
+
{
|
|
103
|
+
apiKey: config.apiKey,
|
|
104
|
+
fallbackPaywall: viewTag,
|
|
105
|
+
triggers: config.triggers || [],
|
|
106
|
+
customUserId: config.customUserId || null,
|
|
107
|
+
customAPIEndpoint: config.customAPIEndpoint || null,
|
|
108
|
+
customUserTraits: config.customUserTraits || {
|
|
109
|
+
"exampleUserTrait": "test_value"
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{}
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// Update the other methods to be synchronous
|
|
117
|
+
export const presentUpsell = (triggerName: string) => {
|
|
118
|
+
HeliumBridge.presentUpsell(triggerName);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const hideUpsell = () => {
|
|
122
|
+
HeliumBridge.hideUpsell();
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// Update the UpsellView component to handle the style prop
|
|
126
|
+
export const UpsellView: React.FC<HeliumUpsellViewProps> = ({ trigger, style }) => {
|
|
127
|
+
const NativeView = getNativeHeliumUpsellView();
|
|
128
|
+
return (
|
|
129
|
+
<NativeView
|
|
130
|
+
trigger={trigger}
|
|
131
|
+
style={[{ flex: 1 }, style]}
|
|
132
|
+
/>
|
|
133
|
+
);
|
|
134
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { HeliumTransactionStatus } from './types';
|
|
2
|
+
|
|
3
|
+
export interface HeliumCallbacks {
|
|
4
|
+
makePurchase: (productId: string) => Promise<string>;
|
|
5
|
+
restorePurchases: () => Promise<boolean>; // Modified to return Promise
|
|
6
|
+
onHeliumPaywallEvent: (event: any) => void;
|
|
7
|
+
getCustomVariableValues: () => Record<string, any>; // Modified to return directly
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Update the implementation
|
|
11
|
+
export class DemoHeliumCallbacks implements HeliumCallbacks {
|
|
12
|
+
private events: { timestamp: Date; event: any }[] = [];
|
|
13
|
+
|
|
14
|
+
async makePurchase(productId: string): Promise<HeliumTransactionStatus> {
|
|
15
|
+
this.events.push({ timestamp: new Date(), event: { type: 'purchase', productId } });
|
|
16
|
+
return 'completed' as HeliumTransactionStatus;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async restorePurchases(): Promise<boolean> {
|
|
20
|
+
this.events.push({ timestamp: new Date(), event: { type: 'restore' } });
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
onHeliumPaywallEvent(event: any): void {
|
|
25
|
+
this.events.push({ timestamp: new Date(), event });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getCustomVariableValues = (): Record<string, any> => {
|
|
29
|
+
console.log('getCustomVariableValues called');
|
|
30
|
+
return {
|
|
31
|
+
exampleVar1: 'value1',
|
|
32
|
+
exampleVar2: 'value2'
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
getEventHistory() {
|
|
37
|
+
return this.events;
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type HeliumTransactionStatus = 'completed' | 'failed' | 'cancelled' | 'pending' | 'restored';
|
|
2
|
+
|
|
3
|
+
export interface HeliumCallbacks {
|
|
4
|
+
makePurchase: (productId: string) => Promise<HeliumTransactionStatus>;
|
|
5
|
+
restorePurchases: () => Promise<boolean>;
|
|
6
|
+
onHeliumPaywallEvent: (event: any) => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface HeliumConfig {
|
|
10
|
+
apiKey: string;
|
|
11
|
+
fallbackView?: number;
|
|
12
|
+
triggers?: string[];
|
|
13
|
+
customUserId?: string;
|
|
14
|
+
customAPIEndpoint?: string;
|
|
15
|
+
customUserTraits?: Record<string, any>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface HeliumUpsellViewProps {
|
|
19
|
+
trigger: string;
|
|
20
|
+
style?: any;
|
|
21
|
+
}
|