1
+ import { createArrayBuffer , pointsFromBuffer } from '@nativescript-community/arraybuffers' ;
1
2
import { Application , Utils } from '@nativescript/core' ;
2
- import { android as androidApp } from '@nativescript/core/application ' ;
3
- import { Attachment , BaseEnvelopeItemHeaders , Breadcrumb , Envelope , EnvelopeItem , Event , SeverityLevel , User } from '@sentry/types ' ;
3
+ import { BaseEnvelopeItemHeaders , Breadcrumb , Envelope , EnvelopeItem , Event , SeverityLevel } from '@sentry/types ' ;
4
+ import { SentryError } from '@sentry/utils ' ;
4
5
import { convertNativescriptFramesToSentryFrames , parseErrorStack } from './integrations/debugsymbolicator' ;
5
- import { UserFeedback } from './wrapper' ;
6
- import { rewriteFrameIntegration } from './sdk' ;
7
- import { SentryError , logger , normalize } from '@sentry/utils' ;
8
- import { NativescriptOptions } from './options' ;
9
- import { createArrayBuffer , pointsFromBuffer } from '@nativescript-community/arraybuffers' ;
10
6
import { isHardCrash } from './misc' ;
7
+ import { NativescriptOptions } from './options' ;
8
+ import { rewriteFrameIntegration } from './sdk' ;
11
9
import { utf8ToBytes } from './vendor' ;
12
10
import { SDK_NAME } from './version' ;
13
- import { TextEncoder } from '@nativescript/core/text' ;
14
- import { Scope } from '@sentry/core' ;
15
- // function utf8ToBytes(str: string) {{
16
- // return new java.lang.String(str).getBytes(java.nio.charset.StandardCharsets.UTF_8);
17
- // }}
18
- // // function utf8ToUint8Array(str: string) {
19
-
20
- // // return new java.lang.String(str).getBytes(java.nio.charset.StandardCharsets.UTF_8);
21
- // // }
22
- // const EOL = utf8ToBytes('\n')[0];
23
-
24
- function isArrayBuffer ( value : unknown ) : boolean {
25
- return ( value instanceof ArrayBuffer || Object . prototype . toString . call ( value ) === '[object ArrayBuffer]' ) ;
26
- }
11
+
27
12
let encoder ;
28
13
function strToTypedArray ( str : string ) {
29
14
if ( ! encoder ) {
@@ -51,76 +36,6 @@ export namespace NATIVE {
51
36
return enableNative ;
52
37
}
53
38
54
- function eventLevel ( level ) {
55
- switch ( level ) {
56
- case 'fatal' :
57
- return io . sentry . SentryLevel . FATAL ;
58
- case 'warning' :
59
- return io . sentry . SentryLevel . WARNING ;
60
- case 'debug' :
61
- return io . sentry . SentryLevel . DEBUG ;
62
- case 'error' :
63
- return io . sentry . SentryLevel . ERROR ;
64
- default :
65
- return io . sentry . SentryLevel . INFO ;
66
- }
67
- }
68
- function getNativeHashMap ( obj : { [ k : string ] : string } ) {
69
- if ( ! obj ) {
70
- return null ;
71
- }
72
- const map = new java . util . HashMap < string , string > ( ) ;
73
- Object . keys ( obj ) . forEach ( ( k ) => {
74
- map . put ( k , obj [ k ] ) ;
75
- } ) ;
76
- return map ;
77
- }
78
- function getJSHashMap ( obj : java . util . HashMap < any , any > ) {
79
- if ( ! obj ) {
80
- return null ;
81
- }
82
-
83
- const result = { } ;
84
- let value , pair , key ;
85
-
86
- const it = obj . entrySet ( ) . iterator ( ) ;
87
- while ( it . hasNext ( ) ) {
88
- pair = it . next ( ) ;
89
- value = pair . getValue ( ) ;
90
- key = pair . getKey ( ) ;
91
- if ( value instanceof java . util . HashMap ) {
92
- result [ key ] = getJSHashMap ( value ) ;
93
- } else if ( value instanceof java . lang . Number ) {
94
- result [ key ] = value . doubleValue ( ) ;
95
- } else if ( value && value . hasOwnProperty ( 'length' ) ) {
96
- result [ key ] = Array . from ( { length : value . length } ) . map ( ( v , i ) => value [ i ] ) ;
97
- } else {
98
- result [ key ] = value ;
99
- }
100
- }
101
-
102
- return result ;
103
- }
104
- function getUser ( user : { [ k : string ] : any } ) {
105
- const nUser = new io . sentry . protocol . User ( ) ;
106
- if ( user . email ) {
107
- nUser . setEmail ( user . email ) ;
108
- }
109
- if ( user . userID ) {
110
- nUser . setId ( user . userID ) ;
111
- } else if ( user . userId ) {
112
- nUser . setId ( user . userId ) ;
113
- } else if ( user . id ) {
114
- nUser . setId ( user . id ) ;
115
- }
116
- if ( user . username ) {
117
- nUser . setUsername ( user . username ) ;
118
- }
119
- if ( user . extra ) {
120
- nUser . setOthers ( getNativeHashMap ( user . extra ) ) ;
121
- }
122
- return nUser ;
123
- }
124
39
const mJsModuleIdPattern = new RegExp ( '(?:^|[/\\\\])(\\d+\\.js)$' ) ;
125
40
function stackFrameToModuleId ( frame : { file ?: string } ) {
126
41
if ( ! ! frame . file ) {
@@ -245,8 +160,6 @@ export namespace NATIVE {
245
160
else if ( level === 'critical' as SeverityLevel ) {
246
161
return 'fatal' as SeverityLevel ;
247
162
}
248
-
249
-
250
163
return level ;
251
164
}
252
165
/**
@@ -278,10 +191,7 @@ export namespace NATIVE {
278
191
console . warn ( 'Event was skipped as native SDK is not enabled.' ) ;
279
192
return ;
280
193
}
281
- // let startTime = Date.now();
282
- const envelopeBytes = prepareEnvelope ( envelope ) ;
283
- // console.log('prepareEnvelope', Date.now() - startTime, 'ms', envelopeBytes.length);
284
- // startTime = Date.now();
194
+ const envelopeBytes = prepareEnvelopeNative ( envelope ) ;
285
195
// const envelopeBytesNative = prepareEnvelopeNative(envelope);
286
196
await captureEnvelope ( envelopeBytes ) ;
287
197
if ( sentryOptions . flushSendEvent ) {
@@ -328,7 +238,7 @@ export namespace NATIVE {
328
238
return envelopeBytes ;
329
239
}
330
240
331
- export function prepareEnvelopeNative ( envelope : Envelope ) {
241
+ export function prepareEnvelopeNative ( envelope : Envelope ) {
332
242
const [ envelopeHeader , envelopeItems ] = envelope ;
333
243
334
244
const headerString = JSON . stringify ( envelopeHeader ) ;
@@ -345,7 +255,6 @@ export namespace NATIVE {
345
255
bytesPayload = itemPayload ;
346
256
} else {
347
257
bytesPayload = strToTypedArray ( JSON . stringify ( itemPayload ) ) ;
348
- // console.log('bytesPayload', JSON.stringify(itemPayload));
349
258
if ( ! hardCrashed ) {
350
259
hardCrashed = isHardCrash ( itemPayload ) ;
351
260
}
@@ -354,7 +263,6 @@ export namespace NATIVE {
354
263
// Content type is not inside BaseEnvelopeItemHeaders.
355
264
( itemHeader as BaseEnvelopeItemHeaders ) . content_type = 'application/json' ;
356
265
( itemHeader as BaseEnvelopeItemHeaders ) . length = bytesPayload . length ;
357
- // const serializedItemHeader = JSON.stringify(itemHeader) + '\n';
358
266
const serializedItemHeaderBytes = strToTypedArray ( JSON . stringify ( itemHeader ) + '\n' ) ;
359
267
360
268
const rawItemBytes = createArrayBuffer ( serializedItemHeaderBytes . length + bytesPayload . length + 1 , true , false ) ;
@@ -535,7 +443,6 @@ export namespace NATIVE {
535
443
// }
536
444
537
445
export async function captureEnvelope ( envelope : string | Uint8Array | number [ ] , { store} : { store ?: boolean } = { } ) {
538
- console . log ( 'captureEnvelope' , envelope . length , nSentryOptions . getOutboxPath ( ) , ArrayBuffer . isView ( envelope ) , Array . isArray ( envelope ) ) ;
539
446
try {
540
447
const outboxPath = new java . io . File ( nSentryOptions . getOutboxPath ( ) , java . util . UUID . randomUUID ( ) . toString ( ) ) ;
541
448
const out = new java . io . FileOutputStream ( outboxPath ) ;
0 commit comments