@prelude.so/react-native-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.
- package/README.md +71 -0
- package/android/build.gradle +47 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/so/prelude/reactnative/sdk/PreludeReactNativeSdkModule.kt +44 -0
- package/build/PreludeReactNativeSdk.types.d.ts +10 -0
- package/build/PreludeReactNativeSdk.types.d.ts.map +1 -0
- package/build/PreludeReactNativeSdk.types.js +2 -0
- package/build/PreludeReactNativeSdk.types.js.map +1 -0
- package/build/PreludeReactNativeSdkModule.d.ts +3 -0
- package/build/PreludeReactNativeSdkModule.d.ts.map +1 -0
- package/build/PreludeReactNativeSdkModule.js +5 -0
- package/build/PreludeReactNativeSdkModule.js.map +1 -0
- package/build/index.d.ts +9 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +8 -0
- package/build/index.js.map +1 -0
- package/expo-module.config.json +9 -0
- package/ios/PreludeReactNativeSdk.podspec +24 -0
- package/ios/PreludeReactNativeSdkModule.swift +27 -0
- package/package.json +55 -0
- package/scripts/postinstall.js +116 -0
- package/src/PreludeReactNativeSdk.types.ts +10 -0
- package/src/PreludeReactNativeSdkModule.ts +5 -0
- package/src/index.ts +14 -0
- package/tsconfig.json +9 -0
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Readme
|
|
2
|
+
### Using the Expo React Native SDK
|
|
3
|
+
|
|
4
|
+
The Expo React Native SDK allows you to capture certain device signals (both in Android and iOS) that will be reported back to Prelude.
|
|
5
|
+
|
|
6
|
+
It is provided as an Expo module that you can integrate into your React Native Expo Application.
|
|
7
|
+
|
|
8
|
+
The Android `minSdkVersion` value in the SDK is set to 26 (Android 8.0). If you application has a lower value you may need to update it.
|
|
9
|
+
|
|
10
|
+
## Configuring the project
|
|
11
|
+
|
|
12
|
+
First install the SDK dependency in your app:
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
npm install @prelude.so/react-native-sdk
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Then, where ever in your application you want to report the device signals you can use code like this:
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
...
|
|
22
|
+
// Import the react state types
|
|
23
|
+
import { useEffect, useState } from "react";
|
|
24
|
+
// Import the SDK types
|
|
25
|
+
import * as PreludeReactNativeSdk from '@prelude.so/react-native-sdk';
|
|
26
|
+
...
|
|
27
|
+
|
|
28
|
+
// Define a state to receive status updates
|
|
29
|
+
const [dispatchStatus, setDispatchStatus] = useState({ dispatchID: "", status: "" });
|
|
30
|
+
|
|
31
|
+
...
|
|
32
|
+
// Subscribe to the event
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
const subscription = PreludeReactNativeSdk.onDispatchingSignals((dispatchingSignalsStatus) => {
|
|
35
|
+
console.log("Dispatch status: " + dispatchingSignalsStatus.status + ". Id: " + dispatchingSignalsStatus.dispatchID);
|
|
36
|
+
setDispatchStatus(dispatchingSignalsStatus);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return () => {
|
|
40
|
+
subscription.remove();
|
|
41
|
+
}
|
|
42
|
+
}, [dispatchStatus]);
|
|
43
|
+
|
|
44
|
+
...
|
|
45
|
+
// Submit the signals in any of your app event handlers (here is a button example)
|
|
46
|
+
<Button title={`Dispatch Signals`} onPress={() =>
|
|
47
|
+
PreludeReactNativeSdk.dispatchSignals({
|
|
48
|
+
sdk_key: "YOUR-SDK-KEY"
|
|
49
|
+
})
|
|
50
|
+
.catch((error) => {
|
|
51
|
+
console.log("Dispatch error: " + error);
|
|
52
|
+
})
|
|
53
|
+
} />
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Then run the Expo application normally (in your application's directory):
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
npx expo run:ios
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
or
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
npx expo run:android
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Once you get the dispatch ID through the event, you can report it back to your own API to be forwarded in subsequent network calls.
|
|
70
|
+
|
|
71
|
+
There is no restriction on when to call this API, you just need to take this action before you need to report back the dispatch ID. It is advisable to make the request early on during the user onboarding process to have the dispatch id available when required.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
apply plugin: 'com.android.library'
|
|
2
|
+
|
|
3
|
+
group = 'so.prelude.reactnative.sdk'
|
|
4
|
+
version = '0.1.0'
|
|
5
|
+
|
|
6
|
+
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
7
|
+
apply from: expoModulesCorePlugin
|
|
8
|
+
applyKotlinExpoModulesCorePlugin()
|
|
9
|
+
useCoreDependencies()
|
|
10
|
+
useExpoPublishing()
|
|
11
|
+
|
|
12
|
+
// If you want to use the managed Android SDK versions from expo-modules-core, set this to true.
|
|
13
|
+
// The Android SDK versions will be bumped from time to time in SDK releases and may introduce breaking changes in your module code.
|
|
14
|
+
// Most of the time, you may like to manage the Android SDK versions yourself.
|
|
15
|
+
def useManagedAndroidSdkVersions = false
|
|
16
|
+
if (useManagedAndroidSdkVersions) {
|
|
17
|
+
useDefaultAndroidSdkVersions()
|
|
18
|
+
} else {
|
|
19
|
+
buildscript {
|
|
20
|
+
// Simple helper that allows the root project to override versions declared by this library.
|
|
21
|
+
ext.safeExtGet = { prop, fallback ->
|
|
22
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
project.android {
|
|
26
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 34)
|
|
27
|
+
defaultConfig {
|
|
28
|
+
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
29
|
+
targetSdkVersion safeExtGet("targetSdkVersion", 34)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
android {
|
|
35
|
+
namespace "so.prelude.reactnative.sdk"
|
|
36
|
+
defaultConfig {
|
|
37
|
+
versionCode 1
|
|
38
|
+
versionName "0.1.0"
|
|
39
|
+
}
|
|
40
|
+
lintOptions {
|
|
41
|
+
abortOnError false
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
dependencies {
|
|
46
|
+
implementation('so.prelude.android:sdk:0.1.0')
|
|
47
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
package so.prelude.reactnative.sdk
|
|
2
|
+
|
|
3
|
+
import expo.modules.kotlin.modules.Module
|
|
4
|
+
import expo.modules.kotlin.modules.ModuleDefinition
|
|
5
|
+
import so.prelude.android.sdk.Configuration
|
|
6
|
+
import so.prelude.android.sdk.Configuration.Companion.DEFAULT_REQUEST_TIMEOUT
|
|
7
|
+
import so.prelude.android.sdk.DispatchStatusListener
|
|
8
|
+
import so.prelude.android.sdk.Endpoint
|
|
9
|
+
import so.prelude.android.sdk.Prelude
|
|
10
|
+
|
|
11
|
+
class PreludeReactNativeSdkModule : Module() {
|
|
12
|
+
override fun definition() = ModuleDefinition {
|
|
13
|
+
Name("PreludeReactNativeSdk")
|
|
14
|
+
|
|
15
|
+
Events("onDispatchingSignals")
|
|
16
|
+
|
|
17
|
+
AsyncFunction("dispatchSignals") { sdkKey: String, endpointUrl: String?, timeoutMilliseconds: Long? ->
|
|
18
|
+
|
|
19
|
+
val endpoint: Endpoint = endpointUrl?.let {
|
|
20
|
+
Endpoint.Custom(it)
|
|
21
|
+
} ?: Endpoint.Default
|
|
22
|
+
|
|
23
|
+
val context = appContext.reactContext
|
|
24
|
+
context?.let {
|
|
25
|
+
Prelude(
|
|
26
|
+
Configuration(
|
|
27
|
+
it.applicationContext,
|
|
28
|
+
sdkKey,
|
|
29
|
+
endpoint,
|
|
30
|
+
requestTimeout = timeoutMilliseconds ?: DEFAULT_REQUEST_TIMEOUT
|
|
31
|
+
)
|
|
32
|
+
)
|
|
33
|
+
.dispatchSignals { status: DispatchStatusListener.Status, dispatchId ->
|
|
34
|
+
sendEvent(
|
|
35
|
+
"onDispatchingSignals", mapOf(
|
|
36
|
+
"status" to status,
|
|
37
|
+
"dispatchID" to dispatchId
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PreludeReactNativeSdk.types.d.ts","sourceRoot":"","sources":["../src/PreludeReactNativeSdk.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,wBAAwB,GAAG;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PreludeReactNativeSdk.types.js","sourceRoot":"","sources":["../src/PreludeReactNativeSdk.types.ts"],"names":[],"mappings":"","sourcesContent":["export type DispatchingSignalsStatus = {\n status: string,\n dispatchID: string;\n};\n\nexport type Configuration = {\n sdk_key: string;\n endpoint?: string;\n timeout_milliseconds?: number;\n}"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PreludeReactNativeSdkModule.d.ts","sourceRoot":"","sources":["../src/PreludeReactNativeSdkModule.ts"],"names":[],"mappings":";AAIA,wBAA4D"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { requireNativeModule } from 'expo-modules-core';
|
|
2
|
+
// It loads the native module object from the JSI or falls back to
|
|
3
|
+
// the bridge module (from NativeModulesProxy) if the remote debugger is on.
|
|
4
|
+
export default requireNativeModule('PreludeReactNativeSdk');
|
|
5
|
+
//# sourceMappingURL=PreludeReactNativeSdkModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PreludeReactNativeSdkModule.js","sourceRoot":"","sources":["../src/PreludeReactNativeSdkModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,kEAAkE;AAClE,4EAA4E;AAC5E,eAAe,mBAAmB,CAAC,uBAAuB,CAAC,CAAC","sourcesContent":["import { requireNativeModule } from 'expo-modules-core';\n\n// It loads the native module object from the JSI or falls back to\n// the bridge module (from NativeModulesProxy) if the remote debugger is on.\nexport default requireNativeModule('PreludeReactNativeSdk');\n"]}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EventSubscription } from 'expo-modules-core';
|
|
2
|
+
import { DispatchingSignalsStatus } from './PreludeReactNativeSdk.types';
|
|
3
|
+
export declare function dispatchSignals(configuration: {
|
|
4
|
+
sdk_key: string;
|
|
5
|
+
endpoint?: string;
|
|
6
|
+
}): Promise<void>;
|
|
7
|
+
export declare function onDispatchingSignals(listener: (event: DispatchingSignalsStatus) => void): EventSubscription;
|
|
8
|
+
export { DispatchingSignalsStatus };
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,wBAAsB,eAAe,CAAC,aAAa,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1G;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,wBAAwB,KAAK,IAAI,GAAG,iBAAiB,CAE3G;AAED,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import PreludeReactNativeSdkModule from './PreludeReactNativeSdkModule';
|
|
2
|
+
export async function dispatchSignals(configuration) {
|
|
3
|
+
return await PreludeReactNativeSdkModule.dispatchSignals(configuration.sdk_key, configuration.endpoint);
|
|
4
|
+
}
|
|
5
|
+
export function onDispatchingSignals(listener) {
|
|
6
|
+
return PreludeReactNativeSdkModule.addListener('onDispatchingSignals', listener);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,2BAA2B,MAAM,+BAA+B,CAAC;AAGxE,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,aAAqD;IACzF,OAAO,MAAM,2BAA2B,CAAC,eAAe,CAAC,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;AAC1G,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,QAAmD;IACtF,OAAO,2BAA2B,CAAC,WAAW,CAAC,sBAAsB,EAAE,QAAQ,CAAC,CAAC;AACnF,CAAC","sourcesContent":["import { EventSubscription } from 'expo-modules-core';\n\nimport PreludeReactNativeSdkModule from './PreludeReactNativeSdkModule';\nimport { DispatchingSignalsStatus } from './PreludeReactNativeSdk.types';\n\nexport async function dispatchSignals(configuration: { sdk_key: string, endpoint?: string }): Promise<void> {\n return await PreludeReactNativeSdkModule.dispatchSignals(configuration.sdk_key, configuration.endpoint);\n}\n\nexport function onDispatchingSignals(listener: (event: DispatchingSignalsStatus) => void): EventSubscription {\n return PreludeReactNativeSdkModule.addListener('onDispatchingSignals', listener);\n}\n\nexport { DispatchingSignalsStatus };\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'PreludeReactNativeSdk'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.description = package['description']
|
|
10
|
+
s.license = package['license']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.homepage = package['homepage']
|
|
13
|
+
s.platforms = { :ios => '15.1', :tvos => '15.1' }
|
|
14
|
+
s.swift_version = '5.4'
|
|
15
|
+
s.source = { git: 'https://github.com/prelude-so/react-native-sdk' }
|
|
16
|
+
s.static_framework = true
|
|
17
|
+
s.dependency 'ExpoModulesCore'
|
|
18
|
+
s.vendored_frameworks = 'sdk/core/PreludeCore.xcframework'
|
|
19
|
+
s.pod_target_xcconfig = {
|
|
20
|
+
'DEFINES_MODULE' => 'YES',
|
|
21
|
+
'SWIFT_COMPILATION_MODE' => 'wholemodule'
|
|
22
|
+
}
|
|
23
|
+
s.source_files = "**/*.swift", "../sdk/**/*.swift"
|
|
24
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
|
|
3
|
+
public class PreludeReactNativeSdkModule: Module {
|
|
4
|
+
public func definition() -> ModuleDefinition {
|
|
5
|
+
Name("PreludeReactNativeSdk")
|
|
6
|
+
|
|
7
|
+
Events("onDispatchingSignals")
|
|
8
|
+
|
|
9
|
+
AsyncFunction("dispatchSignals") { (sdkKey: String, endpointUrl: String?) in
|
|
10
|
+
let endpoint = endpointUrl != nil ? Endpoint.custom(endpointUrl!) : .default
|
|
11
|
+
|
|
12
|
+
let configuration = Configuration(
|
|
13
|
+
sdkKey: sdkKey,
|
|
14
|
+
endpoint: endpoint
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
let prelude = Prelude(configuration)
|
|
18
|
+
|
|
19
|
+
do {
|
|
20
|
+
let dispatchID = try await prelude.dispatchSignals()
|
|
21
|
+
self.sendEvent("onDispatchingSignals", ["status": "SUCCESS", "dispatchID": dispatchID])
|
|
22
|
+
} catch {
|
|
23
|
+
self.sendEvent("onDispatchingSignals", ["status": "FAILURE", "dispatchID": error.localizedDescription])
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@prelude.so/react-native-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Prelude SDK for React Native",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"types": "build/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "expo-module build",
|
|
9
|
+
"clean": "expo-module clean",
|
|
10
|
+
"lint": "expo-module lint",
|
|
11
|
+
"test": "expo-module test",
|
|
12
|
+
"prepare": "expo-module prepare",
|
|
13
|
+
"prepublishOnly": "expo-module prepublishOnly",
|
|
14
|
+
"expo-module": "expo-module",
|
|
15
|
+
"postinstall": "node scripts/postinstall.js"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"react-native",
|
|
19
|
+
"expo",
|
|
20
|
+
"prelude-react-native-sdk",
|
|
21
|
+
"PreludeReactNativeSdk"
|
|
22
|
+
],
|
|
23
|
+
"files": [
|
|
24
|
+
"android/build.gradle",
|
|
25
|
+
"android/src/*",
|
|
26
|
+
"build/*",
|
|
27
|
+
"ios/*",
|
|
28
|
+
"scripts/*",
|
|
29
|
+
"src/*",
|
|
30
|
+
"expo-module.config.json",
|
|
31
|
+
"tsconfig.json"
|
|
32
|
+
],
|
|
33
|
+
"repository": "https://github.com/prelude-so/react-native-sdk",
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/prelude-so/react-native-sdk/issues"
|
|
36
|
+
},
|
|
37
|
+
"author": "Prelude <hello@prelude.so> (https://github.com/prelude-so)",
|
|
38
|
+
"license": "Apache-2.0",
|
|
39
|
+
"homepage": "https://github.com/prelude-so/react-native-sdk#readme",
|
|
40
|
+
"dependencies": {},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/react": "~18.3.12",
|
|
43
|
+
"expo-module-scripts": "^4.0.2",
|
|
44
|
+
"expo": "~52.0.9",
|
|
45
|
+
"react-native": "0.76.2"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"expo": "*",
|
|
49
|
+
"react": "*",
|
|
50
|
+
"react-native": "*"
|
|
51
|
+
},
|
|
52
|
+
"so_prelude": {
|
|
53
|
+
"apple_sdk_tag": "0.1.0"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const child_process = require("node:child_process");
|
|
3
|
+
const util = require("node:util");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { Readable } = require("stream");
|
|
6
|
+
const { finished } = require("stream/promises");
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
const packagePath = path.resolve(__dirname, "../package.json");
|
|
10
|
+
const sdkPath = path.resolve(__dirname, "../ios/sdk");
|
|
11
|
+
if (fs.existsSync(sdkPath)) {
|
|
12
|
+
fs.rmSync(sdkPath, { recursive: true });
|
|
13
|
+
}
|
|
14
|
+
fs.mkdirSync(sdkPath);
|
|
15
|
+
const packageFile = require(packagePath);
|
|
16
|
+
const appleSdkVersion = packageFile.so_prelude.apple_sdk_tag;
|
|
17
|
+
const appleSdkSources =
|
|
18
|
+
process.env.APPLE_SDK_LOCATION ||
|
|
19
|
+
`https://github.com/prelude-so/apple-sdk/archive/refs/tags/${appleSdkVersion}.zip`;
|
|
20
|
+
|
|
21
|
+
await configureSources(appleSdkSources, sdkPath, appleSdkVersion);
|
|
22
|
+
|
|
23
|
+
logSuccess("The Prelude Apple SDK has been successfully configured.");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function configureSources(sourcesPath, localSdkPath, appleSdkVersion) {
|
|
27
|
+
if (sourcesPath.startsWith("http")) {
|
|
28
|
+
await configureFromUrl(sourcesPath, localSdkPath, appleSdkVersion);
|
|
29
|
+
} else {
|
|
30
|
+
fs.cpSync(sourcesPath, localSdkPath, { recursive: true });
|
|
31
|
+
fs.rmSync(`${localSdkPath}/Package.swift`)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function configureFromUrl(url, localSdkPath, appleSdkVersion) {
|
|
36
|
+
logMessage(`Downloading the Prelude Apple SDK version: ${appleSdkVersion}.`);
|
|
37
|
+
|
|
38
|
+
await downloadFile(url, `${localSdkPath}/${appleSdkVersion}.zip`);
|
|
39
|
+
unzip(`${localSdkPath}/${appleSdkVersion}.zip`, `${localSdkPath}/tmp`);
|
|
40
|
+
fs.rmSync(`${localSdkPath}/${appleSdkVersion}.zip`, { force: true });
|
|
41
|
+
const unzipped_to = fs.readdirSync(`${localSdkPath}/tmp`)[0];
|
|
42
|
+
|
|
43
|
+
const swiftPackage = `${localSdkPath}/tmp/${unzipped_to}/Package.swift`;
|
|
44
|
+
const sources = `${localSdkPath}/tmp/${unzipped_to}/Sources`;
|
|
45
|
+
fs.renameSync(sources, `${localSdkPath}/Sources`);
|
|
46
|
+
|
|
47
|
+
const xcframeworkUrl = await extractXcFrameworkUrl(swiftPackage);
|
|
48
|
+
logMessage("Downloading the Prelude Apple SDK binaries...");
|
|
49
|
+
const xcframeworkFileName = xcframeworkUrl.split("/").pop();
|
|
50
|
+
await downloadFile(
|
|
51
|
+
xcframeworkUrl,
|
|
52
|
+
`${localSdkPath}/tmp/${xcframeworkFileName}`,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
unzip(
|
|
56
|
+
`${localSdkPath}/tmp/${xcframeworkFileName}`,
|
|
57
|
+
`${localSdkPath}/tmp/core/`,
|
|
58
|
+
);
|
|
59
|
+
fs.renameSync(`${localSdkPath}/tmp/core/`, `${localSdkPath}/core`);
|
|
60
|
+
|
|
61
|
+
fs.rmSync(`${localSdkPath}/tmp`, { recursive: true, force: true });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function extractXcFrameworkUrl(packageFileName) {
|
|
65
|
+
const readline = require("node:readline");
|
|
66
|
+
const fileStream = fs.createReadStream(packageFileName);
|
|
67
|
+
|
|
68
|
+
const rl = readline.createInterface({
|
|
69
|
+
input: fileStream,
|
|
70
|
+
crlfDelay: Infinity,
|
|
71
|
+
});
|
|
72
|
+
for await (const line of rl) {
|
|
73
|
+
if (line.includes("url:") && line.includes("xcframework.zip")) {
|
|
74
|
+
const xcframeworkUrl = line
|
|
75
|
+
.trim()
|
|
76
|
+
.replace("url:", "")
|
|
77
|
+
.replaceAll('"', "")
|
|
78
|
+
.replace(",", "")
|
|
79
|
+
.trim();
|
|
80
|
+
return xcframeworkUrl;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const downloadFile = async (url, fileName) => {
|
|
86
|
+
const res = await fetch(url);
|
|
87
|
+
if (!res.ok) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
`Error downloading the Prelude Apple SDK. Response: ${res.statusText}. Tried ${url}.`,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
fs.rmSync(fileName, { force: true });
|
|
93
|
+
const fileStream = fs.createWriteStream(fileName, { flags: "wx" });
|
|
94
|
+
await finished(Readable.fromWeb(res.body).pipe(fileStream));
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const exec = util.promisify(child_process.execSync);
|
|
98
|
+
|
|
99
|
+
async function unzip(fileName, destination) {
|
|
100
|
+
const unzip = await exec("unzip " + fileName + " -d " + destination, {
|
|
101
|
+
stdio: "inherit",
|
|
102
|
+
});
|
|
103
|
+
logMessage(unzip.stdout);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function logMessage(msg) {
|
|
107
|
+
console.log(msg);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function logSuccess(msg) {
|
|
111
|
+
console.log(`\x1b[32m ${msg} \x1b[0m`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
(async () => {
|
|
115
|
+
await main();
|
|
116
|
+
})();
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EventSubscription } from 'expo-modules-core';
|
|
2
|
+
|
|
3
|
+
import PreludeReactNativeSdkModule from './PreludeReactNativeSdkModule';
|
|
4
|
+
import { DispatchingSignalsStatus } from './PreludeReactNativeSdk.types';
|
|
5
|
+
|
|
6
|
+
export async function dispatchSignals(configuration: { sdk_key: string, endpoint?: string }): Promise<void> {
|
|
7
|
+
return await PreludeReactNativeSdkModule.dispatchSignals(configuration.sdk_key, configuration.endpoint);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function onDispatchingSignals(listener: (event: DispatchingSignalsStatus) => void): EventSubscription {
|
|
11
|
+
return PreludeReactNativeSdkModule.addListener('onDispatchingSignals', listener);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { DispatchingSignalsStatus };
|
package/tsconfig.json
ADDED