@logbrew/react-native 0.1.1 → 0.1.3

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.
@@ -0,0 +1,147 @@
1
+ #import "LBRNFatalStoreModule.h"
2
+
3
+ #import "LBRNFatalRecordStore.h"
4
+
5
+ #ifdef RCT_NEW_ARCH_ENABLED
6
+ #import <LogBrewReactNativeSpec/LogBrewReactNativeSpec.h>
7
+ #endif
8
+
9
+ static NSDictionary *LBRNStorageError(void)
10
+ {
11
+ return @{ @"status" : @"storage_error" };
12
+ }
13
+
14
+ static NSDictionary *LBRNNormalizeRecord(NSDictionary *record)
15
+ {
16
+ if (![record isKindOfClass:[NSDictionary class]]) {
17
+ return @{};
18
+ }
19
+ id framesValue = record[@"stackFrames"];
20
+ if (![framesValue isKindOfClass:[NSArray class]]) {
21
+ return record;
22
+ }
23
+ NSMutableArray *frames = [NSMutableArray arrayWithCapacity:[framesValue count]];
24
+ for (id value in framesValue) {
25
+ if (![value isKindOfClass:[NSDictionary class]]) {
26
+ return record;
27
+ }
28
+ NSMutableDictionary *frame = [value mutableCopy];
29
+ NSString *filename = frame[@"filename"];
30
+ if ([filename isKindOfClass:[NSString class]]
31
+ && [filename hasPrefix:@"/"]
32
+ && [[filename substringFromIndex:1] rangeOfString:@"/"].location == NSNotFound) {
33
+ frame[@"filename"] = [filename substringFromIndex:1];
34
+ }
35
+ [frames addObject:frame];
36
+ }
37
+ NSMutableDictionary *normalized = [record mutableCopy];
38
+ normalized[@"stackFrames"] = frames;
39
+ return normalized;
40
+ }
41
+
42
+ @interface LBRNFatalStoreModule ()
43
+ #ifdef RCT_NEW_ARCH_ENABLED
44
+ <NativeLogBrewFatalStoreSpec>
45
+ #endif
46
+ @property (nonatomic, nullable) LBRNFatalRecordStore *store;
47
+ @end
48
+
49
+ @implementation LBRNFatalStoreModule
50
+
51
+ RCT_EXPORT_MODULE(LogBrewFatalStore)
52
+
53
+ + (BOOL)requiresMainQueueSetup
54
+ {
55
+ return NO;
56
+ }
57
+
58
+ - (instancetype)init
59
+ {
60
+ self = [super init];
61
+ if (self != nil) {
62
+ NSURL *baseURL =
63
+ [[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory
64
+ inDomains:NSUserDomainMask].firstObject;
65
+ if (baseURL != nil) {
66
+ NSURL *directoryURL = [baseURL URLByAppendingPathComponent:@"LogBrewFatalJS"
67
+ isDirectory:YES];
68
+ LBRNFatalDirectoryPreparation directoryPreparation = ^BOOL(NSURL *preparedURL) {
69
+ NSError *writeError = nil;
70
+ if (![preparedURL setResourceValue:@YES
71
+ forKey:NSURLIsExcludedFromBackupKey
72
+ error:&writeError]
73
+ || writeError != nil) {
74
+ return NO;
75
+ }
76
+ NSNumber *excluded = nil;
77
+ NSError *readError = nil;
78
+ return [preparedURL getResourceValue:&excluded
79
+ forKey:NSURLIsExcludedFromBackupKey
80
+ error:&readError]
81
+ && readError == nil && excluded.boolValue;
82
+ };
83
+ _store = [[LBRNFatalRecordStore alloc]
84
+ initWithDirectoryURL:directoryURL
85
+ directoryPreparation:directoryPreparation];
86
+ }
87
+ }
88
+ return self;
89
+ }
90
+
91
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(writeFatalRecord:(NSDictionary *)record)
92
+ {
93
+ if (self.store == nil) {
94
+ return LBRNStorageError();
95
+ }
96
+ @try {
97
+ return [self.store writeRecord:LBRNNormalizeRecord(record)];
98
+ } @catch (__unused NSException *exception) {
99
+ return LBRNStorageError();
100
+ }
101
+ }
102
+
103
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(readFatalRecord)
104
+ {
105
+ if (self.store == nil) {
106
+ return LBRNStorageError();
107
+ }
108
+ @try {
109
+ return [self.store readRecord];
110
+ } @catch (__unused NSException *exception) {
111
+ return LBRNStorageError();
112
+ }
113
+ }
114
+
115
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(acknowledgeFatalRecord:(NSString *)recordId)
116
+ {
117
+ if (self.store == nil || ![recordId isKindOfClass:[NSString class]]) {
118
+ return LBRNStorageError();
119
+ }
120
+ @try {
121
+ return [self.store acknowledgeRecordId:recordId];
122
+ } @catch (__unused NSException *exception) {
123
+ return LBRNStorageError();
124
+ }
125
+ }
126
+
127
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(discardFatalRecord)
128
+ {
129
+ if (self.store == nil) {
130
+ return LBRNStorageError();
131
+ }
132
+ @try {
133
+ return [self.store discardRecord];
134
+ } @catch (__unused NSException *exception) {
135
+ return LBRNStorageError();
136
+ }
137
+ }
138
+
139
+ #ifdef RCT_NEW_ARCH_ENABLED
140
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
141
+ (const facebook::react::ObjCTurboModule::InitParams &)params
142
+ {
143
+ return std::make_shared<facebook::react::NativeLogBrewFatalStoreSpecJSI>(params);
144
+ }
145
+ #endif
146
+
147
+ @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logbrew/react-native",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "React Native screen, error, trace, action, and network timeline helpers for LogBrew.",
5
5
  "type": "module",
6
6
  "main": "./index.cjs",
@@ -9,7 +9,10 @@
9
9
  "types": "./index.d.ts",
10
10
  "exports": {
11
11
  ".": {
12
- "react-native": "./index.native.js",
12
+ "react-native": {
13
+ "types": "./index.native.d.ts",
14
+ "default": "./index.native.js"
15
+ },
13
16
  "import": {
14
17
  "types": "./index.d.ts",
15
18
  "default": "./index.js"
@@ -31,6 +34,21 @@
31
34
  },
32
35
  "default": "./lifecycle.js"
33
36
  },
37
+ "./global-errors": {
38
+ "react-native": {
39
+ "types": "./global-errors.d.ts",
40
+ "default": "./global-errors.native.js"
41
+ },
42
+ "import": {
43
+ "types": "./global-errors.d.ts",
44
+ "default": "./global-errors.js"
45
+ },
46
+ "require": {
47
+ "types": "./global-errors.d.cts",
48
+ "default": "./global-errors.cjs"
49
+ },
50
+ "default": "./global-errors.js"
51
+ },
34
52
  "./instrumentation": {
35
53
  "import": {
36
54
  "types": "./instrumentation.d.ts",
@@ -102,6 +120,7 @@
102
120
  "index.cjs",
103
121
  "index.js",
104
122
  "index.native.js",
123
+ "index.native.d.ts",
105
124
  "index.d.ts",
106
125
  "index.d.cts",
107
126
  "apollo.cjs",
@@ -116,6 +135,12 @@
116
135
  "lifecycle.js",
117
136
  "lifecycle.d.ts",
118
137
  "lifecycle.d.cts",
138
+ "global-errors.cjs",
139
+ "fatal-replay.cjs",
140
+ "global-errors.js",
141
+ "global-errors.native.js",
142
+ "global-errors.d.ts",
143
+ "global-errors.d.cts",
119
144
  "metadata.cjs",
120
145
  "metadata.js",
121
146
  "native-bridge.cjs",
@@ -134,6 +159,17 @@
134
159
  "metro.js",
135
160
  "metro.d.ts",
136
161
  "metro.d.cts",
162
+ "LogBrewReactNative.podspec",
163
+ "android/build.gradle",
164
+ "android/src/main",
165
+ "android/src/oldarch",
166
+ "android/src/newarch",
167
+ "ios/LBRNFatalRecordStore.h",
168
+ "ios/LBRNFatalRecordStore.m",
169
+ "ios/LBRNFatalStoreModule.h",
170
+ "ios/LBRNFatalStoreModule.mm",
171
+ "react-native.config.js",
172
+ "src",
137
173
  "README.md",
138
174
  "examples"
139
175
  ],
@@ -149,6 +185,14 @@
149
185
  "source-maps"
150
186
  ],
151
187
  "sideEffects": false,
188
+ "codegenConfig": {
189
+ "name": "LogBrewReactNativeSpec",
190
+ "type": "modules",
191
+ "jsSrcsDir": "src",
192
+ "android": {
193
+ "javaPackageName": "co.logbrew.reactnative"
194
+ }
195
+ },
152
196
  "engines": {
153
197
  "node": ">=18"
154
198
  },
@@ -163,6 +207,6 @@
163
207
  "react-native": ">=0.72"
164
208
  },
165
209
  "scripts": {
166
- "test": "node --check index.js && node --check index.cjs && node --check index.native.js && node --check apollo.js && node --check apollo.cjs && node --check instrumentation.js && node --check instrumentation.cjs && node --check lifecycle.js && node --check lifecycle.cjs && node --check metadata.js && node --check metadata.cjs && node --check native-bridge.js && node --check native-bridge.cjs && node --check resource-fetch.js && node --check resource-fetch.cjs && node --check release-artifacts.js && node --check release-artifacts.cjs && node --check metro.js && node --check metro.cjs && node --check examples/index.mjs && node --check examples/apollo-link-spans.mjs && node --check examples/instrumentation-kit.mjs && node --check examples/lifecycle-spans.mjs && node --check examples/native-bridge-scope.mjs && node --check examples/navigation-resource-spans.mjs && node --check examples/readme-example.mjs && node --check examples/real-user-smoke.mjs && node --check examples/resource-fetch-spans.mjs && node --check examples/trace-correlation.mjs && node --test"
210
+ "test": "node --check index.js && node --check index.cjs && node --check index.native.js && node --check apollo.js && node --check apollo.cjs && node --check instrumentation.js && node --check instrumentation.cjs && node --check lifecycle.js && node --check lifecycle.cjs && node --check global-errors.js && node --check global-errors.native.js && node --check global-errors.cjs && node --check fatal-replay.cjs && node --check metadata.js && node --check metadata.cjs && node --check native-bridge.js && node --check native-bridge.cjs && node --check resource-fetch.js && node --check resource-fetch.cjs && node --check release-artifacts.js && node --check release-artifacts.cjs && node --check metro.js && node --check metro.cjs && node --check examples/index.mjs && node --check examples/apollo-link-spans.mjs && node --check examples/instrumentation-kit.mjs && node --check examples/lifecycle-spans.mjs && node --check examples/native-bridge-scope.mjs && node --check examples/navigation-resource-spans.mjs && node --check examples/readme-example.mjs && node --check examples/real-user-smoke.mjs && node --check examples/resource-fetch-spans.mjs && node --check examples/trace-correlation.mjs && node --test"
167
211
  }
168
212
  }
@@ -0,0 +1,11 @@
1
+ export default {
2
+ dependency: {
3
+ platforms: {
4
+ android: {
5
+ packageImportPath: "import co.logbrew.reactnative.LogBrewReactNativePackage;",
6
+ packageInstance: "new LogBrewReactNativePackage()"
7
+ },
8
+ ios: {}
9
+ }
10
+ }
11
+ };
@@ -0,0 +1,11 @@
1
+ import type { CodegenTypes, TurboModule } from "react-native";
2
+ import { TurboModuleRegistry } from "react-native";
3
+
4
+ export interface Spec extends TurboModule {
5
+ writeFatalRecord(record: CodegenTypes.UnsafeObject): CodegenTypes.UnsafeObject;
6
+ readFatalRecord(): CodegenTypes.UnsafeObject;
7
+ acknowledgeFatalRecord(recordId: string): CodegenTypes.UnsafeObject;
8
+ discardFatalRecord(): CodegenTypes.UnsafeObject;
9
+ }
10
+
11
+ export default TurboModuleRegistry.getEnforcing<Spec>("LogBrewFatalStore");