@appspacer/react-native 1.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AppSpacer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # @appspacer/react-native
2
+
3
+ Production-grade OTA update SDK for React Native — push JavaScript bundle updates directly to users' devices with reliability and safety.
4
+
5
+ **[Full Documentation →](https://docs.appspacer.com)**
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @appspacer/react-native
11
+ cd ios && pod install
12
+ ```
13
+
14
+ ### 2. iOS — Update AppDelegate
15
+
16
+ ```objc
17
+ #import <AppSpacerModule.h>
18
+
19
+ - (NSURL *)bundleURL {
20
+ return [AppSpacerModule bundleURL];
21
+ }
22
+ ```
23
+
24
+ ### 3. Android — Update MainApplication
25
+
26
+ ```java
27
+ import com.appspacer.AppSpacerModule;
28
+ import com.appspacer.AppSpacerPackage;
29
+
30
+ // In getPackages():
31
+ packages.add(new AppSpacerPackage());
32
+
33
+ // In getJSBundleFile():
34
+ String customBundle = AppSpacerModule.getCustomBundlePath(this);
35
+ if (customBundle != null) return customBundle;
36
+ return super.getJSBundleFile();
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ### Simple (CodePush-style HOC)
42
+
43
+ The easiest way to use AppSpacer is to wrap your root component with the `withAppSpacer` Higher-Order Component. This automatically checks for updates on app start and resume, and seamlessly shows a native "Update Available" popup if you enable `updateDialog`.
44
+
45
+ ```tsx
46
+ import { withAppSpacer } from '@appspacer/react-native';
47
+
48
+ function App() {
49
+ return <MainApp />;
50
+ }
51
+
52
+ export default withAppSpacer({
53
+ deploymentKey: 'sk_YOUR_DEPLOYMENT_KEY',
54
+ appVersion: '1.0.0',
55
+ updateDialog: true, // Shows a native alert to the user when an update is found
56
+ })(App);
57
+ ```
58
+
59
+ ### With UI control
60
+
61
+ ```tsx
62
+ import { useAppSpacerUpdate, UpdateStatus, InstallMode } from '@appspacer/react-native';
63
+ import { Button, Text, View } from 'react-native';
64
+
65
+ function App() {
66
+ const { status, update, sync, restartApp } = useAppSpacerUpdate();
67
+
68
+ useEffect(() => {
69
+ sync({ installMode: InstallMode.ON_NEXT_RESTART });
70
+ }, []);
71
+
72
+ return (
73
+ <View>
74
+ {status === UpdateStatus.INSTALLED && (
75
+ <Button title="Restart to apply update" onPress={restartApp} />
76
+ )}
77
+ {status === UpdateStatus.UPDATE_AVAILABLE && update && (
78
+ <Text>Update available: {update.description}</Text>
79
+ )}
80
+ <MainApp />
81
+ </View>
82
+ );
83
+ }
84
+ ```
85
+
86
+ ## API
87
+
88
+ | Method | Description |
89
+ |---|---|
90
+ | `withAppSpacer(config)` | HOC to initialize and auto-sync SDK |
91
+ | `AppSpacer.checkForUpdate()` | Check server for updates |
92
+ | `AppSpacer.downloadUpdate()` | Download and verify pending update |
93
+ | `AppSpacer.restartApp()` | Reload app with new bundle |
94
+ | `AppSpacer.sync(opts?)` | Check + download + install lifecycle |
95
+ | `AppSpacer.notifyAppReady()` | Mark update as successful (rollback protection) |
96
+ | `useAppSpacerUpdate()` | React hook for management |
97
+
98
+ For the full API reference, configuration options, and advanced usage see the **[AppSpacer Documentation](https://docs.appspacer.com)**.
99
+
100
+ ## Safety Features
101
+
102
+ - **SHA256 Verification**: Every package is verified before extraction.
103
+ - **Rollback Protection**: If an update crashes during boot, the SDK automatically rolls back to the previous stable version.
104
+ - **Install Reporting**: Adoption tracking and successful install analytics are automatically reported to your AppSpacer dashboard.
105
+
106
+ ## License
107
+
108
+ MIT — see [LICENSE](LICENSE)
@@ -0,0 +1,28 @@
1
+ buildscript {
2
+ repositories {
3
+ google()
4
+ mavenCentral()
5
+ }
6
+ }
7
+
8
+ apply plugin: 'com.android.library'
9
+
10
+ android {
11
+ namespace "com.appspacer"
12
+ compileSdkVersion 34
13
+
14
+ defaultConfig {
15
+ minSdkVersion 23
16
+ targetSdkVersion 34
17
+ }
18
+
19
+ sourceSets {
20
+ main {
21
+ java.srcDirs = ['src/main/java']
22
+ }
23
+ }
24
+ }
25
+
26
+ dependencies {
27
+ implementation 'com.facebook.react:react-android:+'
28
+ }
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,128 @@
1
+ package com.appspacer;
2
+
3
+ import android.content.Context;
4
+ import android.os.Build;
5
+ import android.util.Log;
6
+
7
+ import java.io.File;
8
+ import java.io.FileOutputStream;
9
+ import java.io.PrintWriter;
10
+ import java.io.StringWriter;
11
+ import java.util.ArrayList;
12
+ import java.util.Collections;
13
+ import java.util.List;
14
+ import java.util.UUID;
15
+ import org.json.JSONArray;
16
+ import org.json.JSONObject;
17
+
18
+ public class AppSpacerCrashHandler implements Thread.UncaughtExceptionHandler {
19
+ private static final String TAG = "AppSpacerCrashHandler";
20
+ private static final int MAX_BREADCRUMBS = 50;
21
+
22
+ private final Thread.UncaughtExceptionHandler defaultHandler;
23
+ private final Context context;
24
+ private static boolean isInitialized = false;
25
+
26
+ // Static buffer for diagnostic context
27
+ private static final List<String> breadcrumbs = Collections.synchronizedList(new ArrayList<String>());
28
+ private static String userId = null;
29
+ private static String userMetadata = null;
30
+
31
+ private AppSpacerCrashHandler(Context context) {
32
+ this.context = context.getApplicationContext();
33
+ this.defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
34
+ Thread.setDefaultUncaughtExceptionHandler(this);
35
+ }
36
+
37
+ public static synchronized void init(Context context) {
38
+ if (!isInitialized) {
39
+ new AppSpacerCrashHandler(context);
40
+ isInitialized = true;
41
+ Log.i(TAG, "AppSpacerCrashHandler initialized via context: " + context.getClass().getSimpleName());
42
+ }
43
+ }
44
+
45
+ public static void addBreadcrumb(String message) {
46
+ synchronized (breadcrumbs) {
47
+ if (breadcrumbs.size() >= MAX_BREADCRUMBS) {
48
+ breadcrumbs.remove(0);
49
+ }
50
+ String timestamp = new java.text.SimpleDateFormat("HH:mm:ss.SSS", java.util.Locale.US).format(new java.util.Date());
51
+ breadcrumbs.add("[" + timestamp + "] " + message);
52
+ }
53
+ }
54
+
55
+ public static void setUserIdentity(String id, String metadata) {
56
+ userId = id;
57
+ userMetadata = metadata;
58
+ }
59
+
60
+ @Override
61
+ public void uncaughtException(Thread thread, Throwable throwable) {
62
+ try {
63
+ Log.e(TAG, "Uncaught native exception captured! Processing...");
64
+
65
+ // 1. Gather stack trace
66
+ StringWriter sw = new StringWriter();
67
+ PrintWriter pw = new PrintWriter(sw);
68
+ throwable.printStackTrace(pw);
69
+ String stackTrace = sw.toString();
70
+
71
+ // 2. Format as JSON payload
72
+ JSONObject crashData = new JSONObject();
73
+ String id = "native-" + System.currentTimeMillis() + "-" + UUID.randomUUID().toString().substring(0, 5);
74
+ crashData.put("id", id);
75
+ crashData.put("type", "native");
76
+
77
+ JSONObject payload = new JSONObject();
78
+ payload.put("message", throwable.getMessage() != null ? throwable.getMessage() : throwable.getClass().getName());
79
+ payload.put("stack", stackTrace);
80
+ payload.put("isFatal", true);
81
+ crashData.put("payload", payload.toString());
82
+
83
+ // Enriched Device Info
84
+ JSONObject device = new JSONObject();
85
+ device.put("os", "android");
86
+ device.put("os_version", Build.VERSION.RELEASE);
87
+ device.put("model", Build.MODEL);
88
+ device.put("manufacturer", Build.MANUFACTURER);
89
+ device.put("sdk_int", Build.VERSION.SDK_INT);
90
+ device.put("brand", Build.BRAND);
91
+ crashData.put("device", device);
92
+
93
+ // Breadcrumbs
94
+ JSONArray breadcrumbsArray = new JSONArray();
95
+ synchronized (breadcrumbs) {
96
+ for (String b : breadcrumbs) {
97
+ breadcrumbsArray.put(b);
98
+ }
99
+ }
100
+ crashData.put("breadcrumbs", breadcrumbsArray);
101
+
102
+ // ISO 8601 timestamp
103
+ crashData.put("timestamp", new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", java.util.Locale.US).format(new java.util.Date()));
104
+
105
+ // User Identity
106
+ if (userId != null) {
107
+ crashData.put("user_id", userId);
108
+ }
109
+ if (userMetadata != null) {
110
+ try {
111
+ crashData.put("user_metadata", new JSONObject(userMetadata));
112
+ } catch (Exception ignore) {}
113
+ }
114
+
115
+ // 3. Save to disk synchronously
116
+ Log.d(TAG, "Saving native crash " + id + " to disk synchronously");
117
+ AppSpacerModule.saveCrashToDiskSync(context, id, crashData.toString());
118
+ Log.i(TAG, "Native crash saved. App will now terminate.");
119
+ } catch (Exception e) {
120
+ Log.e(TAG, "Error during crash processing", e);
121
+ }
122
+
123
+ // 4. Call default handler
124
+ if (defaultHandler != null) {
125
+ defaultHandler.uncaughtException(thread, throwable);
126
+ }
127
+ }
128
+ }