@booleanmaths/booleanmaths-rn-sdk 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.
Files changed (37) hide show
  1. package/BooleanmathsRnSdk.podspec +20 -0
  2. package/LICENSE +201 -0
  3. package/README.md +365 -0
  4. package/android/build.gradle +78 -0
  5. package/android/src/main/AndroidManifest.xml +2 -0
  6. package/android/src/main/java/com/booleanmathsrnsdk/BooleanmathsRnSdkModule.kt +126 -0
  7. package/android/src/main/java/com/booleanmathsrnsdk/BooleanmathsRnSdkPackage.kt +31 -0
  8. package/ios/BooleanmathsRnSdk.h +20 -0
  9. package/ios/BooleanmathsRnSdk.mm +56 -0
  10. package/lib/module/BooleanMaths.js +34 -0
  11. package/lib/module/BooleanMaths.js.map +1 -0
  12. package/lib/module/BooleanMaths.native.js +62 -0
  13. package/lib/module/BooleanMaths.native.js.map +1 -0
  14. package/lib/module/NativeBooleanmathsRnSdk.js +9 -0
  15. package/lib/module/NativeBooleanmathsRnSdk.js.map +1 -0
  16. package/lib/module/index.js +5 -0
  17. package/lib/module/index.js.map +1 -0
  18. package/lib/module/package.json +1 -0
  19. package/lib/module/types.js +2 -0
  20. package/lib/module/types.js.map +1 -0
  21. package/lib/typescript/package.json +1 -0
  22. package/lib/typescript/src/BooleanMaths.d.ts +3 -0
  23. package/lib/typescript/src/BooleanMaths.d.ts.map +1 -0
  24. package/lib/typescript/src/BooleanMaths.native.d.ts +3 -0
  25. package/lib/typescript/src/BooleanMaths.native.d.ts.map +1 -0
  26. package/lib/typescript/src/NativeBooleanmathsRnSdk.d.ts +22 -0
  27. package/lib/typescript/src/NativeBooleanmathsRnSdk.d.ts.map +1 -0
  28. package/lib/typescript/src/index.d.ts +4 -0
  29. package/lib/typescript/src/index.d.ts.map +1 -0
  30. package/lib/typescript/src/types.d.ts +47 -0
  31. package/lib/typescript/src/types.d.ts.map +1 -0
  32. package/package.json +189 -0
  33. package/src/BooleanMaths.native.tsx +86 -0
  34. package/src/BooleanMaths.tsx +45 -0
  35. package/src/NativeBooleanmathsRnSdk.ts +22 -0
  36. package/src/index.tsx +7 -0
  37. package/src/types.ts +60 -0
package/package.json ADDED
@@ -0,0 +1,189 @@
1
+ {
2
+ "name": "@booleanmaths/booleanmaths-rn-sdk",
3
+ "version": "0.1.0",
4
+ "description": "React Native SDK for BooleanMaths — track user events and attribution in mobile apps.",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "@booleanmaths/booleanmaths-rn-sdk-source": "./src/index.tsx",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "*.podspec",
22
+ "react-native.config.js",
23
+ "!ios/build",
24
+ "!android/build",
25
+ "!android/gradle",
26
+ "!android/gradlew",
27
+ "!android/gradlew.bat",
28
+ "!android/local.properties",
29
+ "!**/__tests__",
30
+ "!**/__fixtures__",
31
+ "!**/__mocks__",
32
+ "!**/.*"
33
+ ],
34
+ "scripts": {
35
+ "example": "yarn workspace booleanmaths-rn-sdk-example",
36
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
37
+ "prepare": "bob build",
38
+ "typecheck": "tsc",
39
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
40
+ "test": "jest",
41
+ "release": "release-it --only-version",
42
+ "web": "vite",
43
+ "build:web": "vite build"
44
+ },
45
+ "keywords": [
46
+ "react-native",
47
+ "ios",
48
+ "android",
49
+ "booleanmaths",
50
+ "analytics",
51
+ "attribution",
52
+ "event-tracking",
53
+ "turbomodule",
54
+ "sdk"
55
+ ],
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "git+https://github.com/medront/react-native-booleanmaths-sdk.git"
59
+ },
60
+ "author": "Medront (https://github.com/medront)",
61
+ "license": "Apache-2.0",
62
+ "bugs": {
63
+ "url": "https://github.com/medront/react-native-booleanmaths-sdk/issues"
64
+ },
65
+ "homepage": "https://github.com/medront/react-native-booleanmaths-sdk#readme",
66
+ "publishConfig": {
67
+ "access": "public",
68
+ "registry": "https://registry.npmjs.org/"
69
+ },
70
+ "devDependencies": {
71
+ "@commitlint/config-conventional": "^21.0.2",
72
+ "@eslint/compat": "^2.1.0",
73
+ "@eslint/eslintrc": "^3.3.5",
74
+ "@eslint/js": "^10.0.1",
75
+ "@jest/globals": "^29.7.0",
76
+ "@react-native/babel-preset": "0.85.0",
77
+ "@react-native/eslint-config": "0.85.0",
78
+ "@react-native/jest-preset": "0.85.0",
79
+ "@release-it/conventional-changelog": "^11.0.1",
80
+ "@types/react": "^19.2.0",
81
+ "commitlint": "^21.0.2",
82
+ "del-cli": "^7.0.0",
83
+ "eslint": "^9.39.4",
84
+ "eslint-config-prettier": "^10.1.8",
85
+ "eslint-plugin-ft-flow": "^3.0.11",
86
+ "eslint-plugin-prettier": "^5.5.6",
87
+ "jest": "^29.7.0",
88
+ "lefthook": "^2.1.9",
89
+ "prettier": "^3.8.3",
90
+ "react": "19.2.3",
91
+ "react-native": "0.85.0",
92
+ "react-native-builder-bob": "^0.43.0",
93
+ "react-native-web": "~0.21.2",
94
+ "release-it": "^20.2.0",
95
+ "turbo": "^2.9.16",
96
+ "typescript": "^6.0.3"
97
+ },
98
+ "peerDependencies": {
99
+ "react": "*",
100
+ "react-native": "*"
101
+ },
102
+ "workspaces": [
103
+ "example"
104
+ ],
105
+ "packageManager": "yarn@4.11.0",
106
+ "react-native-builder-bob": {
107
+ "source": "src",
108
+ "output": "lib",
109
+ "targets": [
110
+ [
111
+ "module",
112
+ {
113
+ "esm": true
114
+ }
115
+ ],
116
+ [
117
+ "typescript",
118
+ {
119
+ "project": "tsconfig.build.json"
120
+ }
121
+ ]
122
+ ]
123
+ },
124
+ "codegenConfig": {
125
+ "name": "BooleanmathsRnSdkSpec",
126
+ "type": "modules",
127
+ "jsSrcsDir": "src",
128
+ "android": {
129
+ "javaPackageName": "com.booleanmathsrnsdk"
130
+ }
131
+ },
132
+ "prettier": {
133
+ "quoteProps": "consistent",
134
+ "singleQuote": true,
135
+ "tabWidth": 2,
136
+ "trailingComma": "es5",
137
+ "useTabs": false
138
+ },
139
+ "jest": {
140
+ "preset": "@react-native/jest-preset",
141
+ "testEnvironmentOptions": {
142
+ "customExportConditions": [
143
+ "require",
144
+ "react-native",
145
+ "@booleanmaths/booleanmaths-rn-sdk-source"
146
+ ]
147
+ },
148
+ "modulePathIgnorePatterns": [
149
+ "<rootDir>/example/node_modules",
150
+ "<rootDir>/lib/"
151
+ ]
152
+ },
153
+ "commitlint": {
154
+ "extends": [
155
+ "@commitlint/config-conventional"
156
+ ]
157
+ },
158
+ "release-it": {
159
+ "git": {
160
+ "commitMessage": "chore: release ${version}",
161
+ "tagName": "v${version}"
162
+ },
163
+ "npm": {
164
+ "publish": true
165
+ },
166
+ "github": {
167
+ "release": true
168
+ },
169
+ "plugins": {
170
+ "@release-it/conventional-changelog": {
171
+ "preset": {
172
+ "name": "angular"
173
+ }
174
+ }
175
+ }
176
+ },
177
+ "create-react-native-library": {
178
+ "type": "turbo-module",
179
+ "languages": "kotlin-objc",
180
+ "tools": [
181
+ "eslint",
182
+ "jest",
183
+ "lefthook",
184
+ "release-it",
185
+ "vite"
186
+ ],
187
+ "version": "0.63.0"
188
+ }
189
+ }
@@ -0,0 +1,86 @@
1
+ import { Platform } from 'react-native';
2
+ import NativeBooleanmathsRnSdk from './NativeBooleanmathsRnSdk';
3
+ import type { BooleanMathsApi, BooleanMathsEventProperties } from './types';
4
+
5
+ /**
6
+ * The BooleanMaths native SDK currently ships for Android only. There is no
7
+ * iOS artifact yet, so on iOS every call below short-circuits and the SDK
8
+ * behaves as a silent no-op rather than crashing the app.
9
+ */
10
+ const SUPPORTED_PLATFORMS: ReadonlyArray<typeof Platform.OS> = ['android'];
11
+
12
+ const isPlatformSupported = SUPPORTED_PLATFORMS.includes(Platform.OS);
13
+
14
+ /**
15
+ * Both conditions must hold: a platform we ship a native SDK for, and a native
16
+ * module that actually resolved. The second guards against a broken/incomplete
17
+ * native install.
18
+ */
19
+ const isSupported = isPlatformSupported && NativeBooleanmathsRnSdk != null;
20
+
21
+ let hasWarned = false;
22
+
23
+ function warnOnce() {
24
+ if (hasWarned || !__DEV__) {
25
+ return;
26
+ }
27
+
28
+ hasWarned = true;
29
+
30
+ if (!isPlatformSupported) {
31
+ console.warn(
32
+ `[@booleanmaths/booleanmaths-rn-sdk] The BooleanMaths native SDK is not available on ${Platform.OS} ` +
33
+ '(Android only for now). All SDK calls are no-ops on this platform and no ' +
34
+ 'events will be tracked. Gate your calls on `BooleanMaths.isSupported` to ' +
35
+ 'silence this warning — see the README\'s "Platform support" section.'
36
+ );
37
+ return;
38
+ }
39
+
40
+ console.warn(
41
+ '[@booleanmaths/booleanmaths-rn-sdk] The native module could not be found on ' +
42
+ `${Platform.OS}. Rebuild the app after installing the package (a Metro ` +
43
+ 'reload is not enough), and on iOS run `pod install`. All SDK calls are ' +
44
+ 'no-ops until this is fixed.'
45
+ );
46
+ }
47
+
48
+ export const BooleanMaths: BooleanMathsApi = {
49
+ isSupported,
50
+
51
+ initialize(apiKey: string, pixelId: string): void {
52
+ if (!isSupported) {
53
+ warnOnce();
54
+ return;
55
+ }
56
+
57
+ NativeBooleanmathsRnSdk!.initializeSdk(apiKey, pixelId);
58
+ },
59
+
60
+ trackEvent(name: string, properties: BooleanMathsEventProperties = {}): void {
61
+ if (!isSupported) {
62
+ warnOnce();
63
+ return;
64
+ }
65
+
66
+ NativeBooleanmathsRnSdk!.trackEvent(name, properties);
67
+ },
68
+
69
+ handleNotificationIntent(): void {
70
+ if (!isSupported) {
71
+ warnOnce();
72
+ return;
73
+ }
74
+
75
+ NativeBooleanmathsRnSdk!.handleNotificationIntent();
76
+ },
77
+
78
+ getHelloMessage(): string | null {
79
+ if (!isSupported) {
80
+ warnOnce();
81
+ return null;
82
+ }
83
+
84
+ return NativeBooleanmathsRnSdk!.getHelloMessage();
85
+ },
86
+ };
@@ -0,0 +1,45 @@
1
+ import type { BooleanMathsApi, BooleanMathsEventProperties } from './types';
2
+
3
+ /**
4
+ * Web (and any non-React-Native) build of the SDK.
5
+ *
6
+ * There is no BooleanMaths browser SDK behind this wrapper, so every method is
7
+ * a no-op. It exists so that shared code can import and call the SDK
8
+ * unconditionally without platform checks or bundler errors.
9
+ */
10
+ let hasWarned = false;
11
+
12
+ function warnOnce() {
13
+ if (hasWarned || typeof __DEV__ === 'undefined' || !__DEV__) {
14
+ return;
15
+ }
16
+
17
+ hasWarned = true;
18
+
19
+ console.warn(
20
+ '[@booleanmaths/booleanmaths-rn-sdk] The BooleanMaths SDK has no web implementation. ' +
21
+ 'All SDK calls are no-ops on web and no events will be tracked. Gate your ' +
22
+ 'calls on `BooleanMaths.isSupported` to silence this warning.'
23
+ );
24
+ }
25
+
26
+ export const BooleanMaths: BooleanMathsApi = {
27
+ isSupported: false,
28
+
29
+ initialize(_apiKey: string, _pixelId: string): void {
30
+ warnOnce();
31
+ },
32
+
33
+ trackEvent(_name: string, _properties?: BooleanMathsEventProperties): void {
34
+ warnOnce();
35
+ },
36
+
37
+ handleNotificationIntent(): void {
38
+ warnOnce();
39
+ },
40
+
41
+ getHelloMessage(): string | null {
42
+ warnOnce();
43
+ return null;
44
+ },
45
+ };
@@ -0,0 +1,22 @@
1
+ import { TurboModuleRegistry, type TurboModule } from 'react-native';
2
+
3
+ export interface Spec extends TurboModule {
4
+ /**
5
+ * Named `initializeSdk` rather than `initialize` on purpose: `initialize` is
6
+ * already taken by `NativeModule.initialize()` on Android and by
7
+ * `+[NSObject initialize]` on iOS. The public JS API exposes this as
8
+ * `BooleanMaths.initialize()`.
9
+ */
10
+ initializeSdk(apiKey: string, pixelId: string): void;
11
+ trackEvent(name: string, properties: Object): void;
12
+ /** Android only. No-op elsewhere. */
13
+ handleNotificationIntent(): void;
14
+ /** Smoke test that the native bridge is wired up. */
15
+ getHelloMessage(): string;
16
+ }
17
+
18
+ /**
19
+ * `get` rather than `getEnforcing` so that a missing/unlinked native module
20
+ * degrades to a warning instead of throwing at import time.
21
+ */
22
+ export default TurboModuleRegistry.get<Spec>('BooleanmathsRnSdk');
package/src/index.tsx ADDED
@@ -0,0 +1,7 @@
1
+ export { BooleanMaths } from './BooleanMaths';
2
+ export { BooleanMaths as default } from './BooleanMaths';
3
+ export type {
4
+ BooleanMathsApi,
5
+ BooleanMathsEventProperties,
6
+ BooleanMathsPropertyValue,
7
+ } from './types';
package/src/types.ts ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Values allowed inside an event's `properties` payload.
3
+ *
4
+ * The payload is serialized to JSON natively, so only JSON-representable
5
+ * values survive the bridge. Nested objects and arrays are supported.
6
+ */
7
+ export type BooleanMathsPropertyValue =
8
+ | string
9
+ | number
10
+ | boolean
11
+ | null
12
+ | undefined
13
+ | BooleanMathsPropertyValue[]
14
+ | { [key: string]: BooleanMathsPropertyValue };
15
+
16
+ export type BooleanMathsEventProperties = Record<
17
+ string,
18
+ BooleanMathsPropertyValue
19
+ >;
20
+
21
+ export interface BooleanMathsApi {
22
+ /**
23
+ * Initializes the native SDK. Safe to call on any platform; on platforms
24
+ * without native support this is a no-op (see `isSupported`).
25
+ *
26
+ * Calling this more than once is harmless — the native SDK ignores
27
+ * subsequent calls.
28
+ */
29
+ initialize(apiKey: string, pixelId: string): void;
30
+
31
+ /**
32
+ * Records a custom event. Events are persisted locally and synced in the
33
+ * background, so this never blocks and never throws on network failure.
34
+ *
35
+ * No-op if `initialize` has not been called.
36
+ */
37
+ trackEvent(name: string, properties?: BooleanMathsEventProperties): void;
38
+
39
+ /**
40
+ * Forwards the current Activity's intent to the native SDK so deep-link and
41
+ * notification campaign data is attributed.
42
+ *
43
+ * Android only — a no-op on every other platform. Call this from your
44
+ * deep-link handler and once after `initialize`; see the README for why the
45
+ * launch intent needs this.
46
+ */
47
+ handleNotificationIntent(): void;
48
+
49
+ /**
50
+ * Returns the native SDK's hello message, or `null` when there is no native
51
+ * SDK on this platform. Useful as a bridge smoke test.
52
+ */
53
+ getHelloMessage(): string | null;
54
+
55
+ /**
56
+ * `true` only on platforms where a real BooleanMaths native SDK is linked.
57
+ * Currently Android only.
58
+ */
59
+ readonly isSupported: boolean;
60
+ }