1+ import { createArrayBuffer , pointsFromBuffer } from '@nativescript-community/arraybuffers' ;
12import { 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 ' ;
45import { 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' ;
106import { isHardCrash } from './misc' ;
7+ import { NativescriptOptions } from './options' ;
8+ import { rewriteFrameIntegration } from './sdk' ;
119import { utf8ToBytes } from './vendor' ;
1210import { 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+
2712let encoder ;
2813function strToTypedArray ( str : string ) {
2914 if ( ! encoder ) {
@@ -51,76 +36,6 @@ export namespace NATIVE {
5136 return enableNative ;
5237 }
5338
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- }
12439 const mJsModuleIdPattern = new RegExp ( '(?:^|[/\\\\])(\\d+\\.js)$' ) ;
12540 function stackFrameToModuleId ( frame : { file ?: string } ) {
12641 if ( ! ! frame . file ) {
@@ -245,8 +160,6 @@ export namespace NATIVE {
245160 else if ( level === 'critical' as SeverityLevel ) {
246161 return 'fatal' as SeverityLevel ;
247162 }
248-
249-
250163 return level ;
251164 }
252165 /**
@@ -278,10 +191,7 @@ export namespace NATIVE {
278191 console . warn ( 'Event was skipped as native SDK is not enabled.' ) ;
279192 return ;
280193 }
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 ) ;
285195 // const envelopeBytesNative = prepareEnvelopeNative(envelope);
286196 await captureEnvelope ( envelopeBytes ) ;
287197 if ( sentryOptions . flushSendEvent ) {
@@ -328,7 +238,7 @@ export namespace NATIVE {
328238 return envelopeBytes ;
329239 }
330240
331- export function prepareEnvelopeNative ( envelope : Envelope ) {
241+ export function prepareEnvelopeNative ( envelope : Envelope ) {
332242 const [ envelopeHeader , envelopeItems ] = envelope ;
333243
334244 const headerString = JSON . stringify ( envelopeHeader ) ;
@@ -345,7 +255,6 @@ export namespace NATIVE {
345255 bytesPayload = itemPayload ;
346256 } else {
347257 bytesPayload = strToTypedArray ( JSON . stringify ( itemPayload ) ) ;
348- // console.log('bytesPayload', JSON.stringify(itemPayload));
349258 if ( ! hardCrashed ) {
350259 hardCrashed = isHardCrash ( itemPayload ) ;
351260 }
@@ -354,7 +263,6 @@ export namespace NATIVE {
354263 // Content type is not inside BaseEnvelopeItemHeaders.
355264 ( itemHeader as BaseEnvelopeItemHeaders ) . content_type = 'application/json' ;
356265 ( itemHeader as BaseEnvelopeItemHeaders ) . length = bytesPayload . length ;
357- // const serializedItemHeader = JSON.stringify(itemHeader) + '\n';
358266 const serializedItemHeaderBytes = strToTypedArray ( JSON . stringify ( itemHeader ) + '\n' ) ;
359267
360268 const rawItemBytes = createArrayBuffer ( serializedItemHeaderBytes . length + bytesPayload . length + 1 , true , false ) ;
@@ -535,7 +443,6 @@ export namespace NATIVE {
535443 // }
536444
537445 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 ) ) ;
539446 try {
540447 const outboxPath = new java . io . File ( nSentryOptions . getOutboxPath ( ) , java . util . UUID . randomUUID ( ) . toString ( ) ) ;
541448 const out = new java . io . FileOutputStream ( outboxPath ) ;
0 commit comments