Skip to content

Commit b81eeb3

Browse files
committed
Initial commit, not yet working
0 parents  commit b81eeb3

10 files changed

+201
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_STORE

index.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export class ContextManager {
2+
/**
3+
* Setup ContextSDK
4+
* @method setup
5+
* @memberof ContextManager
6+
* @param { string | null } [licenseKey]
7+
* @returns { Promise<boolean> }
8+
* @example
9+
* ContextManager.setup('YOUR_LICENSE_KEY');
10+
*/
11+
setup = function (licenseKey) {};
12+
13+
sdkVersion = function () {};
14+
}
15+
16+
module.exports = new ContextManager();
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// import ContextSDK
2+
3+
// struct RNContextManager {
4+
// static func setup(licenseKey: String) -> Bool {
5+
// return ContextManager.setup(licenseKey: licenseKey)
6+
// }
7+
8+
// static func sdkVersion() -> String {
9+
// return ContextManager.sdkVersion()
10+
// }
11+
// }
12+
13+
14+
import Foundation
15+
import ContextSDK
16+
import React // this import is necessary
17+
18+
19+
@objc(RNContextManager) // This annotation makes the class visible to React Native
20+
class RNContextManager: NSObject {
21+
22+
@objc(setup:resolver:rejecter:)
23+
func setup(licenseKey: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
24+
let success = ContextManager.setup(licenseKey: licenseKey)
25+
if success {
26+
resolve(true)
27+
} else {
28+
reject("E_SETUP_FAILED", "Setup failed with license key", nil)
29+
}
30+
}
31+
32+
@objc(sdkVersionWithResolver:rejecter:)
33+
func sdkVersion(resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
34+
let version = ContextManager.sdkVersion()
35+
if !version.isEmpty {
36+
resolve(version)
37+
} else {
38+
reject("E_NO_VERSION", "Could not retrieve SDK version", nil)
39+
}
40+
}
41+
42+
// This is required by React Native for exporting methods
43+
@objc static func requiresMainQueueSetup() -> Bool {
44+
return false
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#import <React/RCTBridgeModule.h>
2+
3+
@interface RCT_EXTERN_MODULE(RNContextManager, NSObject)
4+
5+
RCT_EXTERN_METHOD(setup:(NSString *)licenseKey resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
6+
RCT_EXTERN_METHOD(sdkVersionWithResolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
7+
8+
@end

package.json

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "react-native-contextsdk",
3+
"version": "4.1.1",
4+
"description": "React Native Library for ContextSDK",
5+
"keywords": [
6+
"react native",
7+
"contextsdk"
8+
],
9+
"homepage": "https://contextsdk.com",
10+
"bugs": {
11+
"email": "[email protected]"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/context-sdk/react-native.git"
16+
},
17+
"types": "types/index.d.ts",
18+
"scripts": {
19+
"start": "node node_modules/react-native/local-cli/cli.js start",
20+
"format": "prettier \"{samples/**/*.{md,js},*.{md,js}}\" --write",
21+
"lint": "eslint --ext .js,.jsx,.ts,.tsx ./*.js",
22+
"generate-types": "npx -p typescript tsc --build tsconfig-types.json",
23+
"append": "node types-scripts/append.js",
24+
"build": "npx -p typescript tsc --build tsconfig.json",
25+
"build-and-generate-types": "rm -rf types lib && npm run build && npm run generate-types && npm run append"
26+
},
27+
"peerDependencies": {
28+
"@types/react": "^18.2.28",
29+
"prop-types": "^15.8.1",
30+
"react": ">=17.0.0",
31+
"react-native": ">=0.66.0"
32+
},
33+
"devDependencies": {
34+
"@babel/core": "^7.23.2",
35+
"@babel/eslint-parser": "^7.21.8",
36+
"@babel/runtime": "^7.22.3",
37+
"@react-native/eslint-config": "^0.72.2",
38+
"@react-native/metro-config": "^0.72.11",
39+
"@tsconfig/react-native": "^3.0.0",
40+
"@types/react-test-renderer": "^18.0.0",
41+
"babel-jest": "^29.5.0",
42+
"eslint": "^8.41.0",
43+
"eslint-plugin-ft-flow": "^2.0.3",
44+
"eslint-plugin-simple-import-sort": "^10.0.0",
45+
"jest": "^29.5.0",
46+
"jsdoc": "^4.0.2",
47+
"metro-react-native-babel-preset": "0.76.8",
48+
"prettier": "^2.8.8",
49+
"react-native-codegen": "^0.71.5",
50+
"react-test-renderer": "18.2.0",
51+
"typescript": "^5.1.3"
52+
},
53+
"engines": {
54+
"node": ">=16"
55+
}
56+
}

react-native-contextsdk.podspec

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
require "json"
4+
5+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
6+
7+
Pod::Spec.new do |s|
8+
s.name = "react-native-contextsdk"
9+
s.version = package["version"]
10+
s.summary = package["description"]
11+
s.documentation_url = "https://docs.contextsdk.com/"
12+
s.license = package["license"]
13+
s.description = package["description"]
14+
s.authors = { "ContextSDK" => "[email protected]" }
15+
s.homepage = "https://contextsdk.com/"
16+
s.platform = :ios, "15.0"
17+
s.module_name = "ContextSDKReactNativeiOS"
18+
s.source = { git: "https://github.com/context-sdk/react-native" }
19+
s.source_files = "ios/*.{xcodeproj}", "ios/RCTContextSDK/*.{h,m,swift}", "ios/RCTContextSDK/Converters/*.{h,m,swift}", "ios/RCTContextSDK/Helpers/*.{h,m,swift}"
20+
s.dependency("React")
21+
s.dependency("ContextSDK", package["version"])
22+
end

tsconfig-types.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"include": [
3+
"index.js"
4+
],
5+
"compilerOptions": {
6+
"declaration": true,
7+
"emitDeclarationOnly": true,
8+
"allowJs": true,
9+
"declarationMap": true,
10+
"skipLibCheck": true,
11+
"outDir": "./types",
12+
"noResolve": true
13+
}
14+
}

types-scripts/append.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const fs = require('fs');
2+
3+
const typesPath = './types/index.d.ts';
4+
const typesData = fs.readFileSync(typesPath);
5+
6+
const appendPath = './types-scripts/native-modules.ts';
7+
const appendData = fs.readFileSync(appendPath);
8+
9+
fs.writeFileSync(typesPath, typesData + '\n\n' + appendData);

types-scripts/native-modules.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//@ts-ignore
2+
declare module 'react-native' {
3+
export interface NativeModulesStatic {
4+
//@ts-ignore
5+
ContextManager: ContextManager;
6+
}
7+
}

types/index.d.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export class ContextManager {
2+
/**
3+
* Setup ContextSDK
4+
* @method setup
5+
* @memberof ContextManager
6+
* @param { string | null } [licenseKey]
7+
* @returns { Promise<boolean> }
8+
* @example
9+
* ContextManager.setup('YOUR_LICENSE_KEY');
10+
*/
11+
setup: (licenseKey?: string | null) => Promise<boolean>;
12+
sdkVersion: () => void;
13+
}
14+
//# sourceMappingURL=index.d.ts.map
15+
16+
//@ts-ignore
17+
declare module 'react-native' {
18+
export interface NativeModulesStatic {
19+
//@ts-ignore
20+
ContextManager: ContextManager;
21+
}
22+
}

0 commit comments

Comments
 (0)