New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

instabug-reactnative

Package Overview
Dependencies
Maintainers
0
Versions
275
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

instabug-reactnative - npm Package Compare versions

Comparing version 10.9.1 to 10.11.0-000139-SNAPSHOT

.prettierrc.js

34

__tests__/apm.spec.js

@@ -7,3 +7,3 @@ /**

import "react-native";
import { NativeModules } from "react-native";
import { NativeModules, Platform } from "react-native";
import "../jest/mockAPM";

@@ -25,2 +25,5 @@ import APM from "../modules/APM";

const endUITrace = sinon.spy(NativeModules.IBGAPM, "endUITrace");
const endAppLaunch = sinon.spy(NativeModules.IBGAPM, "endAppLaunch");
const setNetworkLoggingEnabled = sinon.spy(NativeModules.Instabug, "setNetworkLoggingEnabled");
const _ibgSleep = sinon.spy(NativeModules.IBGAPM, "ibgSleep");

@@ -43,2 +46,15 @@ beforeEach(() => {

it("should call the native method setNetworkEnabledIOS", () => {
Platform.OS = 'ios';
APM.setNetworkEnabledIOS(true);
expect(setNetworkLoggingEnabled.calledOnceWithExactly(true)).toBe(true);
});
it("should call the native method endAppLaunch", () => {
APM.endAppLaunch();
expect(endAppLaunch.calledOnceWithExactly()).toBe(true);
});
it("should call the native method setAutoUITraceEnabled", () => {

@@ -55,9 +71,9 @@ APM.setAutoUITraceEnabled(true);

});
it("should call the native method startExecutionTrace", () => {
APM.startExecutionTrace("trace");
expect(startExecutionTrace.calledOnceWith("trace")).toBe(true);
});
it("should call the native method setExecutionTraceAttribute", () => {

@@ -69,3 +85,3 @@ const trace = APM.startExecutionTrace("trace").then(() => {

});
it("should call the native method endExecutionTrace", () => {

@@ -77,3 +93,3 @@ const trace = APM.startExecutionTrace("trace").then(() => {

});
it("should call the native method startUITrace", () => {

@@ -90,2 +106,8 @@ APM.startUITrace("uiTrace");

});
it("should call the native method _ibgSleep", () => {
APM._ibgSleep();
expect(_ibgSleep.calledOnceWithExactly()).toBe(true);
});
});

@@ -22,2 +22,5 @@ /**

},
IBGAPM: {
networkLog: jest.fn(),
},
};

@@ -37,2 +40,4 @@ });

const networkLog = sinon.spy(NativeModules.Instabug, 'networkLog');
const apmNetworkLog = sinon.spy(NativeModules.IBGAPM, 'networkLog');
const apolloLinkRequestHandler = sinon.spy(NetworkLogger, 'apolloLinkRequestHandler')

@@ -58,2 +63,4 @@ const network = {

NetworkLogger.setNetworkDataObfuscationHandler(null);
apmNetworkLog.resetHistory();
apolloLinkRequestHandler.resetHistory();
});

@@ -104,3 +111,3 @@

expect(networkLog.calledOnceWithExactly(JSON.stringify(network))).toBe(true);
expect(apmNetworkLog.calledOnceWithExactly(JSON.stringify(network))).toBe(true);
});

@@ -144,2 +151,3 @@

expect(networkLog.calledOnceWithExactly(JSON.stringify(newData))).toBe(true);
expect(apmNetworkLog.calledOnceWithExactly(JSON.stringify(newData))).toBe(true);
});

@@ -156,6 +164,25 @@

expect(networkLog.notCalled).toBe(true);
expect(apmNetworkLog.notCalled).toBe(true);
});
it('should test that operationSetContext at apollo handler called', async () => {
const operation = {
setContext : (callback) => callback({ headers : {} }),
operationName : "operationName"
};
const forward = jest.fn();
const operationSetContextMock = sinon.spy(operation, 'setContext')
NetworkLogger.apolloLinkRequestHandler(operation, forward);
expect(operationSetContextMock.calledOnce).toBe(true);
});
it('should test that apollo handler called with catch error', async () => {
const operation = {};
const forward = jest.fn();
NetworkLogger.apolloLinkRequestHandler(operation, forward);
expect(apolloLinkRequestHandler.calledOnce).toBe(true);
});
});
import 'react-native';
import sinon from 'sinon';
import FakeRequest from '../jest/fakeNetworkRequest';
import InstabugConstants from '../utils/InstabugConstants';

@@ -47,3 +48,3 @@ global.XMLHttpRequest = sinon.useFakeXMLHttpRequest();

let requestHeaders = { 'Content-type': 'application/json', 'token': '9u4hiudhi3bf' };
let requestHeaders = { 'content-type': 'application/json', 'token': '9u4hiudhi3bf' };

@@ -91,3 +92,3 @@ Interceptor.enableInterception();

const headers = { 'Content-type': 'application/json', 'Accept': 'text/html' }
const headers = { 'Content-type': 'application/json', 'Accept': 'text/html','Content-Length':144 }
Interceptor.enableInterception();

@@ -173,4 +174,52 @@ Interceptor.setOnDoneCallback((network) => {

});
it('should set gqlQueryName in network object on receiving response', (done) => {
const headers = {};
headers[InstabugConstants.GRAPHQL_HEADER] =
InstabugConstants.GRAPHQL_HEADER;
const responseBody = { data: [{ item: 'first' }, { item: 'second' }] };
Interceptor.enableInterception();
Interceptor.setOnDoneCallback((network) => {
expect(network.gqlQueryName).toEqual(
headers[InstabugConstants.GRAPHQL_HEADER]
);
done();
});
FakeRequest.open(method, url);
FakeRequest.setRequestHeaders(headers);
FakeRequest.send();
FakeRequest.mockResponse(requests[0], null, JSON.stringify(responseBody));
});
it('should set gqlQueryName in network object on receiving response with empty string', (done) => {
const headers = {};
headers[InstabugConstants.GRAPHQL_HEADER] = 'null';
Interceptor.enableInterception();
Interceptor.setOnDoneCallback((network) => {
expect(network.gqlQueryName).toEqual('');
done();
});
FakeRequest.open(method, url);
FakeRequest.setRequestHeaders(headers);
FakeRequest.send();
FakeRequest.mockResponse(requests[0]);
});
it('should set serverErrorMessage in network object on receiving response', (done) => {
const headers = {};
headers[InstabugConstants.GRAPHQL_HEADER] =
InstabugConstants.GRAPHQL_HEADER;
const responseBody = { errors: [{ item: 'first' }, { item: 'second' }] };
Interceptor.enableInterception();
Interceptor.setOnDoneCallback((network) => {
expect(network.serverErrorMessage).toEqual('GraphQLError');
done();
});
FakeRequest.open(method, url);
FakeRequest.setRequestHeaders(headers);
FakeRequest.setResponseType('text');
FakeRequest.send();
FakeRequest.mockResponse(requests[0], null, JSON.stringify(responseBody));
});
});
});

@@ -0,1 +1,8 @@

## 10.11.0 (2021-12-23)
* Adds GraphQL support for APM network traces with proper grouping
* Adds APM.endAppLaunch API
* Bumps Instabug native SDKs to v10.11
* Fixes an issue with iOS sourcemap upload that causes the build to fail
## 10.9.1 (2021-10-13)

@@ -2,0 +9,0 @@

@@ -535,2 +535,8 @@ // Type definitions for instabug-reactnative 8.0

function setProgressHandlerForRequest(handler: () => void): void;
/**
* Apollo Link Request Handler to track network log for graphQL using apollo
* @param {any} operation
* @param {any} forward
*/
function apolloLinkRequestHandler(operation: any, forward: any):any;
}

@@ -562,2 +568,7 @@ export class Trace {

/**
* Ends the current session’s App Launch. Calling this API is optional, App Launches will still be captured and ended automatically by the SDK;
* this API just allows you to change when an App Launch actually ends.
*/
function endAppLaunch(): void;
/**
* Enables or disables APM Network Metric

@@ -564,0 +575,0 @@ * @param {boolean} isEnabled

@@ -13,5 +13,10 @@ jest.mock("NativeModules", () => {

endUITrace: jest.fn(),
endAppLaunch: jest.fn(),
setNetworkEnabledIOS: jest.fn(),
ibgSleep: jest.fn(),
},
Instabug: {},
Instabug: {
setNetworkLoggingEnabled: jest.fn(),
},
};
});

123

jest/mockInstabug.js

@@ -1,61 +0,62 @@

jest.mock('NativeModules', () => {
return {
Instabug: {
startWithToken: jest.fn(),
setUserData: jest.fn(),
setTrackUserSteps: jest.fn(),
setIBGLogPrintsToConsole: jest.fn(),
didSelectPromptOptionHandler: jest.fn(),
setSessionProfilerEnabled: jest.fn(),
setPushNotificationsEnabled: jest.fn(),
setLocale: jest.fn(),
setColorTheme: jest.fn(),
setPrimaryColor: jest.fn(),
appendTags: jest.fn(),
resetTags: jest.fn(),
getTags: jest.fn(cb => cb(['tags1', 'tags2'])),
setString: jest.fn(),
identifyUserWithEmail: jest.fn(),
logOut: jest.fn(),
logUserEventWithName: jest.fn(),
log: jest.fn(),
logVerbose: jest.fn(),
logInfo: jest.fn(),
logWarn: jest.fn(),
logError: jest.fn(),
logDebug: jest.fn(),
clearLogs: jest.fn(),
setReproStepsMode: jest.fn(),
setSdkDebugLogsLevel: jest.fn(),
setUserAttribute: jest.fn(),
getUserAttribute: jest.fn((_, cb) => cb('24')),
removeUserAttribute: jest.fn(),
getAllUserAttributes: jest.fn(cb => cb([{ age: '24' }])),
clearAllUserAttributes: jest.fn(),
setDebugEnabled: jest.fn(),
enable: jest.fn(),
disable: jest.fn(),
isRunningLive: jest.fn(cb => cb(true)),
setVideoRecordingFloatingButtonPosition: jest.fn(),
showWelcomeMessageWithMode: jest.fn(),
setWelcomeMessageMode: jest.fn(),
setFileAttachment: jest.fn(),
hideView: jest.fn(),
show: jest.fn(),
setPreSendingHandler: jest.fn(),
callPrivateApi: jest.fn(),
addListener: jest.fn(),
getReport: jest.fn(),
sendHandledJSCrash: jest.fn(),
sendJSCrash: jest.fn(),
reportScreenChange: jest.fn(),
},
IBGBugReporting: {
setFloatingButtonEdge: jest.fn(),
setEnabledAttachmentTypes: jest.fn(),
},
IBGReplies: {
setPushNotificationsEnabled: jest.fn(),
},
};
});
jest.mock("react-native", () => {
const RN = jest.requireActual("react-native"); // use original implementation, which comes with mocks out of the box
RN.NativeModules.Instabug = {
startWithToken: jest.fn(),
setUserData: jest.fn(),
setTrackUserSteps: jest.fn(),
setIBGLogPrintsToConsole: jest.fn(),
didSelectPromptOptionHandler: jest.fn(),
setSessionProfilerEnabled: jest.fn(),
setPushNotificationsEnabled: jest.fn(),
setLocale: jest.fn(),
setColorTheme: jest.fn(),
setPrimaryColor: jest.fn(),
appendTags: jest.fn(),
resetTags: jest.fn(),
getTags: jest.fn((cb) => cb(["tags1", "tags2"])),
setString: jest.fn(),
identifyUserWithEmail: jest.fn(),
logOut: jest.fn(),
logUserEventWithName: jest.fn(),
log: jest.fn(),
logVerbose: jest.fn(),
logInfo: jest.fn(),
logWarn: jest.fn(),
logError: jest.fn(),
logDebug: jest.fn(),
clearLogs: jest.fn(),
setReproStepsMode: jest.fn(),
setSdkDebugLogsLevel: jest.fn(),
setUserAttribute: jest.fn(),
getUserAttribute: jest.fn((_, cb) => cb("24")),
removeUserAttribute: jest.fn(),
getAllUserAttributes: jest.fn((cb) => cb([{ age: "24" }])),
clearAllUserAttributes: jest.fn(),
setDebugEnabled: jest.fn(),
enable: jest.fn(),
disable: jest.fn(),
isRunningLive: jest.fn((cb) => cb(true)),
setVideoRecordingFloatingButtonPosition: jest.fn(),
showWelcomeMessageWithMode: jest.fn(),
setWelcomeMessageMode: jest.fn(),
setFileAttachment: jest.fn(),
hideView: jest.fn(),
show: jest.fn(),
setPreSendingHandler: jest.fn(),
callPrivateApi: jest.fn(),
addListener: jest.fn(),
getReport: jest.fn(),
sendHandledJSCrash: jest.fn(),
sendJSCrash: jest.fn(),
reportScreenChange: jest.fn(),
};
RN.NativeModules.IBGBugReporting = {
setFloatingButtonEdge: jest.fn(),
setEnabledAttachmentTypes: jest.fn(),
};
RN.NativeModules.IBGReplies = {
setPushNotificationsEnabled: jest.fn(),
};
return RN;
});

@@ -59,2 +59,9 @@ import {

/**
* Ends app launch
*/
endAppLaunch() {
IBGAPM.endAppLaunch();
},
/**
* Enables or disables APM Network Metric

@@ -61,0 +68,0 @@ * @param {boolean} isEnabled

@@ -5,5 +5,4 @@ import { NativeModules, Platform } from 'react-native';

import InstabugConstants from '../utils/InstabugConstants';
let { Instabug } = NativeModules;
let { Instabug, IBGAPM } = NativeModules;
var _networkDataObfuscationHandlerSet = false;

@@ -36,2 +35,3 @@ var _requestFilterExpression = false;

Instabug.networkLog(JSON.stringify(network));
IBGAPM.networkLog(JSON.stringify(network));
} else {

@@ -62,3 +62,4 @@ Instabug.networkLog(network);

IBGEventEmitter.addListener(Instabug,
IBGEventEmitter.addListener(
Instabug,
InstabugConstants.NETWORK_DATA_OBFUSCATION_HANDLER_EVENT,

@@ -70,2 +71,3 @@ async data => {

Instabug.networkLog(JSON.stringify(newData));
IBGAPM.networkLog(JSON.stringify(newData));
} else {

@@ -81,3 +83,2 @@ Instabug.networkLog(newData);

/**

@@ -99,3 +100,14 @@ * Omit requests from being logged based on either their request or response details

apolloLinkRequestHandler(operation, forward) {
try {
operation.setContext(({ headers = {} }) => {
headers[InstabugConstants.GRAPHQL_HEADER] = operation.operationName;
return {headers:headers};
});
} catch (e) {
console.error(e);
}
return forward(operation);
},
};
{
"name": "instabug-reactnative",
"version": "10.9.1",
"version": "10.11.0-000139-SNAPSHOT",
"description": "React Native plugin for integrating the Instabug SDK",

@@ -5,0 +5,0 @@ "main": "index.js",

module.exports = {
dependency: {
platforms: {
ios: {
scriptPhases: [
{
name: '[instabug-reactnative] Upload Sourcemap',
script: 'bash "../node_modules/instabug-reactnative/ios/upload_sourcemap.sh"',
execution_position: 'after_compile',
},
],
},
ios: {},
android: {

@@ -14,0 +6,0 @@ },

@@ -11,3 +11,4 @@ export default {

DID_DISMISS_SURVEY_HANDLER: 'IBGDidDismissSurvey',
DID_SELECT_PROMPT_OPTION_HANDLER: 'IBGDidSelectPromptOptionHandler'
DID_SELECT_PROMPT_OPTION_HANDLER: 'IBGDidSelectPromptOptionHandler',
GRAPHQL_HEADER: 'IBGGraphQLHeader',
};
'use strict';
import InstabugConstants from './InstabugConstants';
const XMLHttpRequest = global.XMLHttpRequest;

@@ -29,4 +31,7 @@ const originalXHROpen = XMLHttpRequest.prototype.open;

duration: 0,
gqlQueryName: '',
serverErrorMessage: '',
requestContentType: '',
};
}
};

@@ -41,3 +46,3 @@ const XHRInterceptor = {

enableInterception() {
XMLHttpRequest.prototype.open = function(method, url) {
XMLHttpRequest.prototype.open = function (method, url) {
_reset();

@@ -49,18 +54,19 @@ network.url = url;

XMLHttpRequest.prototype.setRequestHeader = function(header, value) {
XMLHttpRequest.prototype.setRequestHeader = function (header, value) {
if (network.requestHeaders === '') {
network.requestHeaders = {};
}
network.requestHeaders[header] = typeof value === 'string' ? value : JSON.stringify(value);
network.requestHeaders[header] =
typeof value === 'string' ? value : JSON.stringify(value);
originalXHRSetRequestHeader.apply(this, arguments);
};
XMLHttpRequest.prototype.send = function(data) {
XMLHttpRequest.prototype.send = function (data) {
var cloneNetwork = JSON.parse(JSON.stringify(network));
cloneNetwork.requestBody = data ? data : '';
if (typeof cloneNetwork.requestBody !== "string") {
if (typeof cloneNetwork.requestBody !== 'string') {
cloneNetwork.requestBody = JSON.stringify(cloneNetwork.requestBody);
}
if (this.addEventListener) {

@@ -78,13 +84,16 @@ this.addEventListener(

}
const responseBodySizeString = this.getResponseHeader('Content-Length');
const responseBodySizeString =
this.getResponseHeader('Content-Length');
if (responseBodySizeString) {
const responseBodySizeNumber = Number(responseBodySizeString);
if (!isNaN(responseBodySizeNumber)) cloneNetwork.responseBodySize = responseBodySizeNumber;
if (!isNaN(responseBodySizeNumber))
cloneNetwork.responseBodySize = responseBodySizeNumber;
}
if (this.getAllResponseHeaders()) {
const responseHeaders = this.getAllResponseHeaders().split('\r\n');
const responseHeaders =
this.getAllResponseHeaders().split('\r\n');
const responseHeadersDictionary = {};
responseHeaders.forEach(element => {
responseHeaders.forEach((element) => {
const key = element.split(/:(.+)/)[0];

@@ -96,5 +105,10 @@ const value = element.split(/:(.+)/)[1];

}
if(cloneNetwork.requestHeaders['content-type']){
cloneNetwork.requestContentType = cloneNetwork.requestHeaders['content-type'].split(';')[0];
}
}
if (this.readyState === this.DONE) {
cloneNetwork.duration = (Date.now() - cloneNetwork.startTime);
cloneNetwork.duration = Date.now() - cloneNetwork.startTime;
if (this.status == null) {

@@ -105,19 +119,58 @@ cloneNetwork.responseCode = 0;

}
if (this._hasError) {
cloneNetwork.errorCode = 0;
cloneNetwork.errorDomain = 'ClientError';
cloneNetwork.requestBody =
typeof this._response === 'string'
? this._response
: JSON.stringify(this._response);
cloneNetwork.responseBody = null;
}
if (this.response) {
if (this.responseType === 'blob') {
var responseText = await (new Response(this.response)).text();
var responseText = await new Response(this.response).text();
cloneNetwork.responseBody = responseText;
} else if (this.responseType === 'text' || this.responseType === '') {
} else if (
this.responseType === 'text' ||
this.responseType === ''
) {
cloneNetwork.responseBody = this.response;
}
}
cloneNetwork.requestBodySize = cloneNetwork.requestBody.length;
if(cloneNetwork.responseBodySize === 0){
cloneNetwork.responseBodySize = cloneNetwork.responseBody.length;
}
if (this._hasError) {
cloneNetwork.errorCode = 0;
cloneNetwork.errorDomain = 'ClientError';
if (
cloneNetwork.requestHeaders[InstabugConstants.GRAPHQL_HEADER]
) {
cloneNetwork.gqlQueryName =
cloneNetwork.requestHeaders[InstabugConstants.GRAPHQL_HEADER];
delete cloneNetwork.requestHeaders[
InstabugConstants.GRAPHQL_HEADER
];
if (cloneNetwork.gqlQueryName === 'null') {
cloneNetwork.gqlQueryName = '';
}
if (cloneNetwork.responseBody) {
let responseObj = JSON.parse(cloneNetwork.responseBody);
cloneNetwork.requestBody = typeof this._response === "string" ? this._response : JSON.stringify(this._response);
cloneNetwork.responseBody = null;
if (responseObj.errors) {
cloneNetwork.serverErrorMessage = 'GraphQLError';
} else {
cloneNetwork.serverErrorMessage = '';
}
}
}
else
{
delete cloneNetwork.gqlQueryName;
}
if (onDoneCallback) {

@@ -131,3 +184,3 @@ onDoneCallback(cloneNetwork);

const downloadUploadProgressCallback = event => {
const downloadUploadProgressCallback = (event) => {
if (!isInterceptorEnabled) {

@@ -144,3 +197,6 @@ return;

this.addEventListener('progress', downloadUploadProgressCallback);
this.upload.addEventListener('progress', downloadUploadProgressCallback);
this.upload.addEventListener(
'progress',
downloadUploadProgressCallback
);
}

@@ -161,5 +217,5 @@

onProgressCallback = null;
}
},
};
module.exports = XHRInterceptor;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc