txlemetry-react-native 4.55.1
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 +353 -0
- package/README.md +13 -0
- package/dist/PostHogContext.d.ts +5 -0
- package/dist/PostHogContext.js +1 -0
- package/dist/PostHogErrorBoundary.d.ts +27 -0
- package/dist/PostHogErrorBoundary.js +1 -0
- package/dist/PostHogMaskView.d.ts +39 -0
- package/dist/PostHogMaskView.js +1 -0
- package/dist/PostHogProvider.d.ts +100 -0
- package/dist/PostHogProvider.js +1 -0
- package/dist/autocapture.d.ts +4 -0
- package/dist/autocapture.js +1 -0
- package/dist/error-tracking/index.d.ts +98 -0
- package/dist/error-tracking/index.js +1 -0
- package/dist/error-tracking/utils.d.ts +5 -0
- package/dist/error-tracking/utils.js +1 -0
- package/dist/frameworks/wix-navigation.d.ts +3 -0
- package/dist/frameworks/wix-navigation.js +1 -0
- package/dist/hooks/useFeatureFlag.d.ts +5 -0
- package/dist/hooks/useFeatureFlag.js +1 -0
- package/dist/hooks/useFeatureFlagResult.d.ts +3 -0
- package/dist/hooks/useFeatureFlagResult.js +1 -0
- package/dist/hooks/useFeatureFlags.d.ts +3 -0
- package/dist/hooks/useFeatureFlags.js +1 -0
- package/dist/hooks/useNavigationTracker.d.ts +6 -0
- package/dist/hooks/useNavigationTracker.js +1 -0
- package/dist/hooks/usePostHog.d.ts +2 -0
- package/dist/hooks/usePostHog.js +1 -0
- package/dist/hooks/utils.d.ts +14 -0
- package/dist/hooks/utils.js +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +1 -0
- package/dist/index.txlemetry.d.ts +36 -0
- package/dist/index.txlemetry.js +21 -0
- package/dist/logs-defaults.d.ts +9 -0
- package/dist/logs-defaults.js +1 -0
- package/dist/native-deps.d.ts +4 -0
- package/dist/native-deps.js +1 -0
- package/dist/optional/OptionalAsyncStorage.d.ts +2 -0
- package/dist/optional/OptionalAsyncStorage.js +1 -0
- package/dist/optional/OptionalExpoApplication.d.ts +2 -0
- package/dist/optional/OptionalExpoApplication.js +1 -0
- package/dist/optional/OptionalExpoDevice.d.ts +2 -0
- package/dist/optional/OptionalExpoDevice.js +1 -0
- package/dist/optional/OptionalExpoFileSystem.d.ts +2 -0
- package/dist/optional/OptionalExpoFileSystem.js +1 -0
- package/dist/optional/OptionalExpoFileSystemLegacy.d.ts +2 -0
- package/dist/optional/OptionalExpoFileSystemLegacy.js +1 -0
- package/dist/optional/OptionalExpoLocalization.d.ts +2 -0
- package/dist/optional/OptionalExpoLocalization.js +1 -0
- package/dist/optional/OptionalPlugin.d.ts +20 -0
- package/dist/optional/OptionalPlugin.js +1 -0
- package/dist/optional/OptionalReactNativeDeviceInfo.d.ts +2 -0
- package/dist/optional/OptionalReactNativeDeviceInfo.js +1 -0
- package/dist/optional/OptionalReactNativeLocalize.d.ts +13 -0
- package/dist/optional/OptionalReactNativeLocalize.js +1 -0
- package/dist/optional/OptionalReactNativeNavigation.d.ts +2 -0
- package/dist/optional/OptionalReactNativeNavigation.js +1 -0
- package/dist/optional/OptionalReactNativeNavigationWix.d.ts +2 -0
- package/dist/optional/OptionalReactNativeNavigationWix.js +1 -0
- package/dist/optional/OptionalReactNativeSafeArea.d.ts +2 -0
- package/dist/optional/OptionalReactNativeSafeArea.js +1 -0
- package/dist/optional/OptionalReactNativeSvg.d.ts +2 -0
- package/dist/optional/OptionalReactNativeSvg.js +1 -0
- package/dist/posthog-rn.d.ts +1096 -0
- package/dist/posthog-rn.js +1 -0
- package/dist/storage.d.ts +41 -0
- package/dist/storage.js +1 -0
- package/dist/surveys/PostHogSurveyProvider.d.ts +23 -0
- package/dist/surveys/PostHogSurveyProvider.js +1 -0
- package/dist/surveys/components/BottomSection.d.ts +9 -0
- package/dist/surveys/components/BottomSection.js +1 -0
- package/dist/surveys/components/Cancel.d.ts +5 -0
- package/dist/surveys/components/Cancel.js +1 -0
- package/dist/surveys/components/ConfirmationMessage.d.ts +12 -0
- package/dist/surveys/components/ConfirmationMessage.js +1 -0
- package/dist/surveys/components/QuestionHeader.d.ts +8 -0
- package/dist/surveys/components/QuestionHeader.js +1 -0
- package/dist/surveys/components/QuestionTypes.d.ts +26 -0
- package/dist/surveys/components/QuestionTypes.js +1 -0
- package/dist/surveys/components/SurveyModal.d.ts +11 -0
- package/dist/surveys/components/SurveyModal.js +1 -0
- package/dist/surveys/components/Surveys.d.ts +16 -0
- package/dist/surveys/components/Surveys.js +1 -0
- package/dist/surveys/getActiveMatchingSurveys.d.ts +2 -0
- package/dist/surveys/getActiveMatchingSurveys.js +1 -0
- package/dist/surveys/icons.d.ts +11 -0
- package/dist/surveys/icons.js +1 -0
- package/dist/surveys/index.d.ts +6 -0
- package/dist/surveys/index.js +1 -0
- package/dist/surveys/safeStyleSheet.d.ts +8 -0
- package/dist/surveys/safeStyleSheet.js +1 -0
- package/dist/surveys/survey-translations.d.ts +7 -0
- package/dist/surveys/survey-translations.js +1 -0
- package/dist/surveys/surveys-utils.d.ts +54 -0
- package/dist/surveys/surveys-utils.js +1 -0
- package/dist/surveys/useActivatedSurveys.d.ts +3 -0
- package/dist/surveys/useActivatedSurveys.js +1 -0
- package/dist/surveys/useSurveyStorage.d.ts +8 -0
- package/dist/surveys/useSurveyStorage.js +1 -0
- package/dist/tooling/expoconfig.d.ts +64 -0
- package/dist/tooling/expoconfig.js +1 -0
- package/dist/tooling/metroconfig.d.ts +21 -0
- package/dist/tooling/metroconfig.js +1 -0
- package/dist/tooling/posthogMetroSerializer.d.ts +17 -0
- package/dist/tooling/posthogMetroSerializer.js +1 -0
- package/dist/tooling/utils.d.ts +58 -0
- package/dist/tooling/utils.js +1 -0
- package/dist/tooling/vendor/expo/expoconfig.d.ts +23 -0
- package/dist/tooling/vendor/expo/expoconfig.js +1 -0
- package/dist/tooling/vendor/metro/countLines.d.ts +2 -0
- package/dist/tooling/vendor/metro/countLines.js +1 -0
- package/dist/tooling/vendor/metro/utils.d.ts +22 -0
- package/dist/tooling/vendor/metro/utils.js +1 -0
- package/dist/types.d.ts +205 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +25 -0
- package/dist/utils.js +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/package.json +149 -0
- package/tooling/txlemetry-xcode.sh +222 -0
- package/tooling/txlemetry.gradle +407 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.defaultSurveyAppearance=exports.defaultRatingLabelOpacity=exports.defaultDescriptionOpacity=exports.defaultBackgroundColor=exports.canActivateRepeatedly=void 0;exports.getContrastingTextColor=getContrastingTextColor;exports.getDisplayOrderQuestions=exports.getDisplayOrderChoices=void 0;exports.getNextSurveyStep=getNextSurveyStep;exports.isMatchingRegex=exports.hasEvents=void 0;exports.matchPropertyFilters=matchPropertyFilters;exports.resolveSurveyAlignment=resolveSurveyAlignment;exports.shouldRenderDescription=shouldRenderDescription;exports.surveyValidationMap=void 0;var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _core=require("@txlemetry/core");var isValidRegex=function isValidRegex(str){try{new RegExp(str);return true;}catch(_a){return false;}};var isMatchingRegex=exports.isMatchingRegex=function isMatchingRegex(value,pattern){if(!isValidRegex(pattern)){return false;}try{return new RegExp(pattern).test(value);}catch(_a){return false;}};var surveyValidationMap=exports.surveyValidationMap=(0,_defineProperty2["default"])((0,_defineProperty2["default"])((0,_defineProperty2["default"])((0,_defineProperty2["default"])((0,_defineProperty2["default"])((0,_defineProperty2["default"])((0,_defineProperty2["default"])((0,_defineProperty2["default"])({},_core.SurveyMatchType.Icontains,function(targets,values){return values.some(function(value){return targets.some(function(target){return value.toLowerCase().includes(target.toLowerCase());});});}),_core.SurveyMatchType.NotIcontains,function(targets,values){return values.every(function(value){return targets.every(function(target){return!value.toLowerCase().includes(target.toLowerCase());});});}),_core.SurveyMatchType.Regex,function(targets,values){return values.some(function(value){return targets.some(function(target){return isMatchingRegex(value,target);});});}),_core.SurveyMatchType.NotRegex,function(targets,values){return values.every(function(value){return targets.every(function(target){return!isMatchingRegex(value,target);});});}),_core.SurveyMatchType.Exact,function(targets,values){return values.some(function(value){return targets.some(function(target){return value===target;});});}),_core.SurveyMatchType.IsNot,function(targets,values){return values.every(function(value){return targets.every(function(target){return value!==target;});});}),"gt",function gt(targets,values){return values.some(function(value){var numValue=parseFloat(value);return!isNaN(numValue)&&targets.some(function(t){return numValue>parseFloat(t);});});}),"lt",function lt(targets,values){return values.some(function(value){var numValue=parseFloat(value);return!isNaN(numValue)&&targets.some(function(t){return numValue<parseFloat(t);});});});function matchPropertyFilters(propertyFilters,eventProperties){if(!propertyFilters){return true;}return Object.entries(propertyFilters).every(function(_ref){var _ref2=(0,_slicedToArray2["default"])(_ref,2),propertyName=_ref2[0],filter=_ref2[1];var eventPropertyValue=eventProperties===null||eventProperties===void 0?void 0:eventProperties[propertyName];if(eventPropertyValue===undefined||eventPropertyValue===null){return false;}var values=[String(eventPropertyValue)];var comparisonFunction=surveyValidationMap[filter.operator];if(!comparisonFunction){return false;}return comparisonFunction(filter.values,values);});}function isInteger(value){return typeof value==='number'&&Number.isInteger(value);}function shouldRenderDescription(description,contentType){var effectiveContentType=contentType!==null&&contentType!==void 0?contentType:_core.SurveyQuestionDescriptionContentType.Text;return Boolean(description&&effectiveContentType===_core.SurveyQuestionDescriptionContentType.Text);}var defaultBackgroundColor=exports.defaultBackgroundColor='#eeeded';var defaultDescriptionOpacity=exports.defaultDescriptionOpacity=0.8;var defaultRatingLabelOpacity=exports.defaultRatingLabelOpacity=0.7;var defaultSurveyAppearance=exports.defaultSurveyAppearance={backgroundColor:defaultBackgroundColor,submitButtonColor:'black',submitButtonTextColor:'white',ratingButtonColor:'white',ratingButtonActiveColor:'black',inputBackground:'white',borderColor:'#c9c6c6',placeholder:'Start typing...',displayThankYouMessage:true,thankYouMessageHeader:'Thank you for your feedback!',position:_core.SurveyPosition.Center,submitButtonText:'Submit',autoDisappear:false,thankYouMessageDescription:'',thankYouMessageDescriptionContentType:_core.SurveyQuestionDescriptionContentType.Text,thankYouMessageCloseButtonText:'Close',surveyPopupDelaySeconds:0,allowGoBack:false,backButtonText:'Back'};var KNOWN_SURVEY_POSITIONS=new Set(Object.values(_core.SurveyPosition));var warnedUnknownPositions=new Set();function resolveSurveyAlignment(position){var resolvedPosition=defaultSurveyAppearance.position;if(position){if(KNOWN_SURVEY_POSITIONS.has(position)){resolvedPosition=position;}else if(!warnedUnknownPositions.has(position)){warnedUnknownPositions.add(position);console.warn("[PostHog.surveys] Unknown survey position ".concat(JSON.stringify(position)," \u2014 falling back to ").concat(defaultSurveyAppearance.position,". Expected one of: ").concat(Object.values(_core.SurveyPosition).join(', '),"."));}}var isTop=resolvedPosition===_core.SurveyPosition.TopLeft||resolvedPosition===_core.SurveyPosition.TopCenter||resolvedPosition===_core.SurveyPosition.TopRight;var isMiddle=resolvedPosition===_core.SurveyPosition.MiddleLeft||resolvedPosition===_core.SurveyPosition.MiddleCenter||resolvedPosition===_core.SurveyPosition.MiddleRight;var isLeft=resolvedPosition===_core.SurveyPosition.TopLeft||resolvedPosition===_core.SurveyPosition.MiddleLeft||resolvedPosition===_core.SurveyPosition.Left;var isRight=resolvedPosition===_core.SurveyPosition.TopRight||resolvedPosition===_core.SurveyPosition.MiddleRight||resolvedPosition===_core.SurveyPosition.Right;return{vertical:isTop?'flex-start':isMiddle?'center':'flex-end',horizontal:isLeft?'flex-start':isRight?'flex-end':'center'};}var getDisplayOrderQuestions=exports.getDisplayOrderQuestions=function getDisplayOrderQuestions(survey){survey.questions.forEach(function(question,idx){question.originalQuestionIndex=idx;});return survey.questions;};var hasEvents=exports.hasEvents=function hasEvents(survey){var _a,_b;return((_b=(_a=survey.conditions)===null||_a===void 0?void 0:_a.events)===null||_b===void 0?void 0:_b.values)!==undefined&&survey.conditions.events.values.length>0;};var canActivateRepeatedly=exports.canActivateRepeatedly=function canActivateRepeatedly(survey){var _a,_b;return!!(((_b=(_a=survey.conditions)===null||_a===void 0?void 0:_a.events)===null||_b===void 0?void 0:_b.repeatedActivation)&&hasEvents(survey))||survey.schedule===_core.SurveySchedule.Always;};var getDisplayOrderChoices=exports.getDisplayOrderChoices=function getDisplayOrderChoices(question){return question.choices;};function getRatingBucketForResponseValue(responseValue,scale){if(scale===3){if(responseValue<1||responseValue>3){console.warn('Txlemetry Debug: Rating response out of range for scale 3:',responseValue);return'neutral';}return responseValue===1?'negative':responseValue===2?'neutral':'positive';}else if(scale===5){if(responseValue<1||responseValue>5){console.warn('Txlemetry Debug: Rating response out of range for scale 5:',responseValue);return'neutral';}return responseValue<=2?'negative':responseValue===3?'neutral':'positive';}else if(scale===7){if(responseValue<1||responseValue>7){console.warn('Txlemetry Debug: Rating response out of range for scale 7:',responseValue);return'neutral';}return responseValue<=3?'negative':responseValue===4?'neutral':'positive';}else if(scale===10){if(responseValue<0||responseValue>10){console.warn('Txlemetry Debug: Rating response out of range for scale 10:',responseValue);return'passives';}return responseValue<=6?'detractors':responseValue<=8?'passives':'promoters';}console.warn('Txlemetry Debug: Unsupported rating scale:',scale);return'neutral';}function getNextSurveyStep(survey,currentQuestionIndex,response){var _a,_b,_c,_d,_e;var question=survey.questions[currentQuestionIndex];var nextQuestionIndex=currentQuestionIndex+1;if(!((_a=question.branching)===null||_a===void 0?void 0:_a.type)){if(currentQuestionIndex===survey.questions.length-1){return _core.SurveyQuestionBranchingType.End;}return nextQuestionIndex;}if(question.branching.type===_core.SurveyQuestionBranchingType.End){return _core.SurveyQuestionBranchingType.End;}else if(question.branching.type===_core.SurveyQuestionBranchingType.SpecificQuestion){if(isInteger(question.branching.index)){return question.branching.index;}}else if(question.branching.type===_core.SurveyQuestionBranchingType.ResponseBased){if(question.type===_core.SurveyQuestionType.SingleChoice){var selectedChoiceIndex=question.choices.indexOf("".concat(response));if(selectedChoiceIndex===-1&&question.hasOpenChoice){selectedChoiceIndex=question.choices.length-1;}if((_c=(_b=question.branching)===null||_b===void 0?void 0:_b.responseValues)===null||_c===void 0?void 0:_c.hasOwnProperty(selectedChoiceIndex)){var nextStep=question.branching.responseValues[selectedChoiceIndex];if(isInteger(nextStep)){return nextStep;}if(nextStep===_core.SurveyQuestionBranchingType.End){return _core.SurveyQuestionBranchingType.End;}return nextQuestionIndex;}}else if(question.type===_core.SurveyQuestionType.Rating){if(!isInteger(response)){console.warn('Txlemetry Debug: Expected integer response for rating question but received:',response);return nextQuestionIndex;}var ratingQuestion=question;var ratingBucket=getRatingBucketForResponseValue(response,ratingQuestion.scale);if((_e=(_d=question.branching)===null||_d===void 0?void 0:_d.responseValues)===null||_e===void 0?void 0:_e.hasOwnProperty(ratingBucket)){var _nextStep=question.branching.responseValues[ratingBucket];if(isInteger(_nextStep)){return _nextStep;}if(_nextStep===_core.SurveyQuestionBranchingType.End){return _core.SurveyQuestionBranchingType.End;}return nextQuestionIndex;}}return nextQuestionIndex;}console.warn('Falling back to next question index due to unexpected branching type');return nextQuestionIndex;}function getContrastingTextColor(color){var rgb;if(color.startsWith('#')){rgb=hex2rgb(color);}if(color.startsWith('rgb')){rgb=color;}var nameColorToHex=nameToHex(color);if(nameColorToHex){rgb=hex2rgb(nameColorToHex);}if(!rgb){return'black';}var colorMatch=rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/);if(colorMatch){var r=parseInt(colorMatch[1],10);var g=parseInt(colorMatch[2],10);var b=parseInt(colorMatch[3],10);var hsp=Math.sqrt(0.299*(r*r)+0.587*(g*g)+0.114*(b*b));return hsp>127.5?'black':'white';}return'black';}function hex2rgb(c){if(c.startsWith('#')){var hexColor=c.replace(/^#/,'');if(/^[0-9A-Fa-f]{3}$/.test(hexColor)){hexColor=hexColor[0]+hexColor[0]+hexColor[1]+hexColor[1]+hexColor[2]+hexColor[2];}if(!/^[0-9A-Fa-f]{6}$/.test(hexColor)){return'rgb(255, 255, 255)';}var r=parseInt(hexColor.slice(0,2),16);var g=parseInt(hexColor.slice(2,4),16);var b=parseInt(hexColor.slice(4,6),16);return"rgb(".concat(r,",").concat(g,",").concat(b,")");}return'rgb(255, 255, 255)';}function nameToHex(name){return{aliceblue:'#f0f8ff',antiquewhite:'#faebd7',aqua:'#00ffff',aquamarine:'#7fffd4',azure:'#f0ffff',beige:'#f5f5dc',bisque:'#ffe4c4',black:'#000000',blanchedalmond:'#ffebcd',blue:'#0000ff',blueviolet:'#8a2be2',brown:'#a52a2a',burlywood:'#deb887',cadetblue:'#5f9ea0',chartreuse:'#7fff00',chocolate:'#d2691e',coral:'#ff7f50',cornflowerblue:'#6495ed',cornsilk:'#fff8dc',crimson:'#dc143c',cyan:'#00ffff',darkblue:'#00008b',darkcyan:'#008b8b',darkgoldenrod:'#b8860b',darkgray:'#a9a9a9',darkgreen:'#006400',darkkhaki:'#bdb76b',darkmagenta:'#8b008b',darkolivegreen:'#556b2f',darkorange:'#ff8c00',darkorchid:'#9932cc',darkred:'#8b0000',darksalmon:'#e9967a',darkseagreen:'#8fbc8f',darkslateblue:'#483d8b',darkslategray:'#2f4f4f',darkturquoise:'#00ced1',darkviolet:'#9400d3',deeppink:'#ff1493',deepskyblue:'#00bfff',dimgray:'#696969',dodgerblue:'#1e90ff',firebrick:'#b22222',floralwhite:'#fffaf0',forestgreen:'#228b22',fuchsia:'#ff00ff',gainsboro:'#dcdcdc',ghostwhite:'#f8f8ff',gold:'#ffd700',goldenrod:'#daa520',gray:'#808080',green:'#008000',greenyellow:'#adff2f',honeydew:'#f0fff0',hotpink:'#ff69b4','indianred ':'#cd5c5c',indigo:'#4b0082',ivory:'#fffff0',khaki:'#f0e68c',lavender:'#e6e6fa',lavenderblush:'#fff0f5',lawngreen:'#7cfc00',lemonchiffon:'#fffacd',lightblue:'#add8e6',lightcoral:'#f08080',lightcyan:'#e0ffff',lightgoldenrodyellow:'#fafad2',lightgrey:'#d3d3d3',lightgreen:'#90ee90',lightpink:'#ffb6c1',lightsalmon:'#ffa07a',lightseagreen:'#20b2aa',lightskyblue:'#87cefa',lightslategray:'#778899',lightsteelblue:'#b0c4de',lightyellow:'#ffffe0',lime:'#00ff00',limegreen:'#32cd32',linen:'#faf0e6',magenta:'#ff00ff',maroon:'#800000',mediumaquamarine:'#66cdaa',mediumblue:'#0000cd',mediumorchid:'#ba55d3',mediumpurple:'#9370d8',mediumseagreen:'#3cb371',mediumslateblue:'#7b68ee',mediumspringgreen:'#00fa9a',mediumturquoise:'#48d1cc',mediumvioletred:'#c71585',midnightblue:'#191970',mintcream:'#f5fffa',mistyrose:'#ffe4e1',moccasin:'#ffe4b5',navajowhite:'#ffdead',navy:'#000080',oldlace:'#fdf5e6',olive:'#808000',olivedrab:'#6b8e23',orange:'#ffa500',orangered:'#ff4500',orchid:'#da70d6',palegoldenrod:'#eee8aa',palegreen:'#98fb98',paleturquoise:'#afeeee',palevioletred:'#d87093',papayawhip:'#ffefd5',peachpuff:'#ffdab9',peru:'#cd853f',pink:'#ffc0cb',plum:'#dda0dd',powderblue:'#b0e0e6',purple:'#800080',red:'#ff0000',rosybrown:'#bc8f8f',royalblue:'#4169e1',saddlebrown:'#8b4513',salmon:'#fa8072',sandybrown:'#f4a460',seagreen:'#2e8b57',seashell:'#fff5ee',sienna:'#a0522d',silver:'#c0c0c0',skyblue:'#87ceeb',slateblue:'#6a5acd',slategray:'#708090',snow:'#fffafa',springgreen:'#00ff7f',steelblue:'#4682b4',tan:'#d2b48c',teal:'#008080',thistle:'#d8bfd8',tomato:'#ff6347',turquoise:'#40e0d0',violet:'#ee82ee',wheat:'#f5deb3',white:'#ffffff',whitesmoke:'#f5f5f5',yellow:'#ffff00',yellowgreen:'#9acd32'}[name.toLowerCase()];}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.useActivatedSurveys=useActivatedSurveys;var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _react=require("react");var _surveysUtils=require("./surveys-utils");function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var _n=0,F=function F(){};return{s:F,n:function n(){return _n>=r.length?{done:!0}:{done:!1,value:r[_n++]};},e:function e(r){throw r;},f:F};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}var o,a=!0,u=!1;return{s:function s(){t=t.call(r);},n:function n(){var r=t.next();return a=r.done,r;},e:function e(r){u=!0,o=r;},f:function f(){try{a||null==t["return"]||t["return"]();}finally{if(u)throw o;}}};}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0;}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n;}var SURVEY_SHOWN_EVENT_NAME='survey shown';function useActivatedSurveys(posthog,surveys){var _useState=(0,_react.useState)(new Set()),_useState2=(0,_slicedToArray2["default"])(_useState,2),activatedSurveys=_useState2[0],setActivatedSurveys=_useState2[1];var eventMap=(0,_react.useMemo)(function(){var _a,_b,_c,_d;var newEventMap=new Map();var _iterator=_createForOfIteratorHelper(surveys.filter(_surveysUtils.hasEvents)),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var survey=_step.value;var _iterator2=_createForOfIteratorHelper((_c=(_b=(_a=survey.conditions)===null||_a===void 0?void 0:_a.events)===null||_b===void 0?void 0:_b.values)!==null&&_c!==void 0?_c:[]),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var event=_step2.value;var configs=(_d=newEventMap.get(event.name))!==null&&_d!==void 0?_d:[];configs.push({surveyId:survey.id,propertyFilters:event.propertyFilters});newEventMap.set(event.name,configs);}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}}}catch(err){_iterator.e(err);}finally{_iterator.f();}return newEventMap;},[surveys]);(0,_react.useEffect)(function(){if(eventMap.size>0){return posthog.on('capture',function(payload){var _a,_b;if(eventMap.has(payload.event)){var configs=(_a=eventMap.get(payload.event))!==null&&_a!==void 0?_a:[];var matchingSurveyIds=configs.filter(function(config){return(0,_surveysUtils.matchPropertyFilters)(config.propertyFilters,payload.properties);}).map(function(config){return config.surveyId;});if(matchingSurveyIds.length>0){setActivatedSurveys(function(current){return new Set([].concat((0,_toConsumableArray2["default"])(current),(0,_toConsumableArray2["default"])(matchingSurveyIds)));});}}else if(payload.event===SURVEY_SHOWN_EVENT_NAME){var surveyId=(_b=payload.properties)===null||_b===void 0?void 0:_b.$survey_id;if(surveyId){setActivatedSurveys(function(current){if(!current.has(surveyId)){return current;}var next=new Set(current);next["delete"](surveyId);return next;});}}});}},[eventMap,posthog]);return activatedSurveys;}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.useSurveyStorage=useSurveyStorage;var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _core=require("@txlemetry/core");var _react=require("react");var _usePostHog=require("../hooks/usePostHog");function useSurveyStorage(){var posthogStorage=(0,_usePostHog.usePostHog)();var _useState=(0,_react.useState)(undefined),_useState2=(0,_slicedToArray2["default"])(_useState,2),lastSeenSurveyDate=_useState2[0],setLastSeenSurveyDate=_useState2[1];var _useState3=(0,_react.useState)([]),_useState4=(0,_slicedToArray2["default"])(_useState3,2),seenSurveys=_useState4[0],setSeenSurveys=_useState4[1];(0,_react.useEffect)(function(){posthogStorage.ready().then(function(){var lastSeenSurveyDate=posthogStorage.getPersistedProperty(_core.PostHogPersistedProperty.SurveyLastSeenDate);if(typeof lastSeenSurveyDate==='string'){setLastSeenSurveyDate(new Date(lastSeenSurveyDate));}var serialisedSeenSurveys=posthogStorage.getPersistedProperty(_core.PostHogPersistedProperty.SurveysSeen);if(typeof serialisedSeenSurveys==='string'){var parsedSeenSurveys=JSON.parse(serialisedSeenSurveys);if(Array.isArray(parsedSeenSurveys)&&typeof parsedSeenSurveys[0]==='string'){setSeenSurveys(parsedSeenSurveys);}}});},[posthogStorage]);return{seenSurveys:seenSurveys,setSeenSurvey:(0,_react.useCallback)(function(surveyId){setSeenSurveys(function(current){var newValue=[surveyId].concat((0,_toConsumableArray2["default"])(current.filter(function(id){return id!==surveyId;})));posthogStorage.setPersistedProperty(_core.PostHogPersistedProperty.SurveysSeen,JSON.stringify(newValue.slice(0,20)));return newValue;});},[posthogStorage]),lastSeenSurveyDate:lastSeenSurveyDate,setLastSeenSurveyDate:(0,_react.useCallback)(function(date){setLastSeenSurveyDate(date);posthogStorage.setPersistedProperty(_core.PostHogPersistedProperty.SurveyLastSeenDate,date.toISOString());},[posthogStorage])};}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export declare function buildAndroidSkipOnConflictGradleLine(skipOnConflict: boolean): string | null;
|
|
2
|
+
export declare function addPostHogAndroidGradlePluginClasspath(projectBuildGradle: string): {
|
|
3
|
+
contents: string;
|
|
4
|
+
classpathPresent: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare function applyPostHogAndroidGradlePlugin(appBuildGradle: string): string;
|
|
7
|
+
type BuildPhase = {
|
|
8
|
+
shellScript: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function modifyExistingXcodeBuildScript(script: BuildPhase, skipOnConflict?: boolean): void;
|
|
11
|
+
export declare function addPostHogWithBundledScriptsToBundleShellScript(script: string, skipOnConflict?: boolean): string;
|
|
12
|
+
export declare function buildDsymUploadShellScript(includeSource?: boolean): string;
|
|
13
|
+
export declare function addDsymUploadBuildPhase(xcodeProject: any, includeSource?: boolean): void;
|
|
14
|
+
export declare function disableUserScriptSandboxing(xcodeProject: any): void;
|
|
15
|
+
type PostHogPluginProps = {
|
|
16
|
+
/**
|
|
17
|
+
* Whether to disable Xcode's user script sandboxing (ENABLE_USER_SCRIPT_SANDBOXING=NO).
|
|
18
|
+
*
|
|
19
|
+
* posthog-cli reads .git/ during sourcemap uploads for release auto-detection;
|
|
20
|
+
* sandboxing (on by default in Xcode 14+) blocks that, so uploads lose git info
|
|
21
|
+
* or fail silently.
|
|
22
|
+
*
|
|
23
|
+
* Default: true (disable sandboxing so uploads "just work").
|
|
24
|
+
* Set to false if your org requires sandboxing stays on —
|
|
25
|
+
* you'll lose automatic git metadata on sourcemap uploads on iOS builds only.
|
|
26
|
+
*
|
|
27
|
+
* Note that this setting is recommended in the Expo docs:
|
|
28
|
+
* https://docs.expo.dev/brownfield/integrated-approach/#configuring-your-xcode-project
|
|
29
|
+
*/
|
|
30
|
+
disableSandboxing?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to upload native debug symbols so native crashes can be symbolicated.
|
|
33
|
+
*
|
|
34
|
+
* When enabled, the plugin wires the native symbol-upload tooling that the
|
|
35
|
+
* native PostHog SDKs already ship:
|
|
36
|
+
* - iOS: a build phase that runs posthog-ios's `upload-symbols.sh`
|
|
37
|
+
* (`posthog-cli dsym upload`).
|
|
38
|
+
* - Android: the official `com.posthog.android` Gradle plugin, which uploads
|
|
39
|
+
* ProGuard/R8 mapping files and injects the matching map-id into the app.
|
|
40
|
+
*
|
|
41
|
+
* Pass `{ includeSource: true }` to also upload native source files so PostHog
|
|
42
|
+
* can show source-code context around native crashes. This is **iOS only** —
|
|
43
|
+
* the Android proguard upload has no source-inclusion equivalent, so the flag
|
|
44
|
+
* is ignored there. Note it uploads your source code to PostHog, hence opt-in.
|
|
45
|
+
*
|
|
46
|
+
* Default: false. Pair this with `errorTracking.autocapture.nativeCrashes` at
|
|
47
|
+
* runtime — without uploaded symbols, native stack traces won't be symbolicated.
|
|
48
|
+
* Requires `posthog-cli` to be available and authenticated during release builds.
|
|
49
|
+
*/
|
|
50
|
+
uploadNativeSymbols?: boolean | {
|
|
51
|
+
includeSource?: boolean;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Whether to append `--skip-on-conflict` to `posthog-cli hermes upload` on iOS and Android.
|
|
55
|
+
*
|
|
56
|
+
* Default: false.
|
|
57
|
+
*/
|
|
58
|
+
skipOnConflict?: boolean;
|
|
59
|
+
};
|
|
60
|
+
export declare function resolveNativeSymbolUpload(prop: PostHogPluginProps['uploadNativeSymbols']): {
|
|
61
|
+
enabled: boolean;
|
|
62
|
+
includeSource: boolean;
|
|
63
|
+
};
|
|
64
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.addDsymUploadBuildPhase=addDsymUploadBuildPhase;exports.addPostHogAndroidGradlePluginClasspath=addPostHogAndroidGradlePluginClasspath;exports.addPostHogWithBundledScriptsToBundleShellScript=addPostHogWithBundledScriptsToBundleShellScript;exports.applyPostHogAndroidGradlePlugin=applyPostHogAndroidGradlePlugin;exports.buildAndroidSkipOnConflictGradleLine=buildAndroidSkipOnConflictGradleLine;exports.buildDsymUploadShellScript=buildDsymUploadShellScript;exports.disableUserScriptSandboxing=disableUserScriptSandboxing;exports.modifyExistingXcodeBuildScript=modifyExistingXcodeBuildScript;exports.resolveNativeSymbolUpload=resolveNativeSymbolUpload;var _typeof2=_interopRequireDefault(require("@babel/runtime/helpers/typeof"));var _require=require('@expo/config-plugins'),withAppBuildGradle=_require.withAppBuildGradle,withProjectBuildGradle=_require.withProjectBuildGradle,withXcodeProject=_require.withXcodeProject;var POSTHOG_ANDROID_GRADLE_PLUGIN_VERSION='1.2.0';var resolvePostHogReactNativePackageJsonPath="[\"node\", \"--print\", \"require('path').join(require('path').dirname(require.resolve('txlemetry-react-native')), '..', 'tooling', 'txlemetry.gradle')\"].execute().text.trim()";var POSTHOG_ANDROID_SKIP_ON_CONFLICT_PROPERTY='posthogReactNativeSkipOnConflict';function buildAndroidSkipOnConflictGradleLine(skipOnConflict){if(!skipOnConflict){return null;}return"project.ext.".concat(POSTHOG_ANDROID_SKIP_ON_CONFLICT_PROPERTY," = true");}var withAndroidPlugin=function withAndroidPlugin(config){var skipOnConflict=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return withAppBuildGradle(config,function(config){if(config.modResults.language!=='groovy'){console.warn('Cannot configure Txlemetry in the app gradle because the build.gradle is not groovy');}var buildGradle=config.modResults.contents;var applyFrom="apply from: new File(".concat(resolvePostHogReactNativePackageJsonPath,")");var skipOnConflictLine=buildAndroidSkipOnConflictGradleLine(skipOnConflict);var applyBlock=skipOnConflictLine?"".concat(skipOnConflictLine,"\n").concat(applyFrom):applyFrom;var skipOnConflictPattern=new RegExp("^project\\.ext\\.".concat(POSTHOG_ANDROID_SKIP_ON_CONFLICT_PROPERTY,"\\s*=\\s*(true|false)\\n?"),'m');if(buildGradle.includes(applyFrom)){var contents=buildGradle.replace(skipOnConflictPattern,'');if(skipOnConflictLine){contents=contents.replace(applyFrom,"".concat(skipOnConflictLine,"\n").concat(applyFrom));}config.modResults.contents=contents;return config;}var pattern=/^android\s*\{/m;if(buildGradle.match(pattern)){config.modResults.contents=buildGradle.replace(pattern,"".concat(applyBlock,"\n\nandroid {"));}else{console.warn('PostHog: Could not find "android {" block in build.gradle');}return config;});};function matchingBraceIndex(s,openBraceIndex){var depth=0;for(var i=openBraceIndex;i<s.length;i++){if(s[i]==='{'){depth++;}else if(s[i]==='}'){depth--;if(depth===0){return i;}}}return-1;}function addPostHogAndroidGradlePluginClasspath(projectBuildGradle){if(projectBuildGradle.includes('posthog-android-gradle-plugin')){return{contents:projectBuildGradle,classpathPresent:true};}var classpathLine=" classpath(\"com.posthog:posthog-android-gradle-plugin:".concat(POSTHOG_ANDROID_GRADLE_PLUGIN_VERSION,"\")");var buildscriptMatch=/buildscript\s*\{/.exec(projectBuildGradle);var buildscriptOpenBrace=buildscriptMatch?buildscriptMatch.index+buildscriptMatch[0].length-1:-1;var buildscriptEnd=buildscriptOpenBrace===-1?-1:matchingBraceIndex(projectBuildGradle,buildscriptOpenBrace);var buildscriptBody=buildscriptEnd===-1?'':projectBuildGradle.slice(buildscriptOpenBrace,buildscriptEnd);var dependenciesMatch=buildscriptBody?/dependencies\s*\{/.exec(buildscriptBody):null;if(!dependenciesMatch){console.warn('PostHog: Could not find a buildscript dependencies block in the project build.gradle; '+'skipping the com.posthog.android classpath. Native symbols will not be uploaded.');return{contents:projectBuildGradle,classpathPresent:false};}var insertAt=buildscriptOpenBrace+dependenciesMatch.index+dependenciesMatch[0].length;return{contents:"".concat(projectBuildGradle.slice(0,insertAt),"\n").concat(classpathLine).concat(projectBuildGradle.slice(insertAt)),classpathPresent:true};}function applyPostHogAndroidGradlePlugin(appBuildGradle){if(/apply plugin: ["']com\.posthog\.android["']/.test(appBuildGradle)){return appBuildGradle;}var applyLine='apply plugin: "com.posthog.android"';var appPluginPattern=/^([ \t]*apply plugin: ["']com\.android\.application["'].*)$/m;if(appPluginPattern.test(appBuildGradle)){return appBuildGradle.replace(appPluginPattern,"$1\n".concat(applyLine));}var androidBlockPattern=/^android\s*\{/m;if(androidBlockPattern.test(appBuildGradle)){return appBuildGradle.replace(androidBlockPattern,"".concat(applyLine,"\n\nandroid {"));}console.warn('PostHog: Could not find where to apply com.posthog.android in the app build.gradle');return appBuildGradle;}var withAndroidNativeSymbolsPlugin=function withAndroidNativeSymbolsPlugin(config){var classpathPresent=false;config=withProjectBuildGradle(config,function(config){if(config.modResults.language!=='groovy'){console.warn('Cannot configure the Txlemetry Android Gradle plugin because the project build.gradle is not groovy');return config;}var result=addPostHogAndroidGradlePluginClasspath(config.modResults.contents);config.modResults.contents=result.contents;classpathPresent=result.classpathPresent;return config;});return withAppBuildGradle(config,function(config){if(config.modResults.language!=='groovy'){console.warn('Cannot configure the Txlemetry Android Gradle plugin because the app build.gradle is not groovy');return config;}if(!classpathPresent){return config;}config.modResults.contents=applyPostHogAndroidGradlePlugin(config.modResults.contents);return config;});};function modifyExistingXcodeBuildScript(script){var skipOnConflict=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(!script.shellScript.match(/(packager|scripts)\/react-native-xcode\.sh\b/)){return;}if(script.shellScript.includes('txlemetry-xcode.sh')){var _code=JSON.parse(script.shellScript);script.shellScript=JSON.stringify(updatePostHogSkipOnConflictArg(_code,skipOnConflict));return;}if(script.shellScript.includes('txlemetry-react-native')){return;}var code=JSON.parse(script.shellScript);script.shellScript=JSON.stringify(addPostHogWithBundledScriptsToBundleShellScript(code,skipOnConflict));}var POSTHOG_REACT_NATIVE_XCODE_PATH="`\"$NODE_BINARY\" --print \"require('path').join(require('path').dirname(require.resolve('txlemetry-react-native')), '..', 'tooling', 'txlemetry-xcode.sh')\"`";var REACT_NATIVE_XCODE_LINE=/^([ \t]*)(?![A-Za-z_][A-Za-z0-9_]*=)(?:\/bin\/sh\s+)?([^\n]*(?:packager|scripts)\/react-native-xcode\.sh\b[^\n]*)$/m;function updatePostHogSkipOnConflictArg(script,skipOnConflict){var skipArg='--posthog-skip-on-conflict --';var withoutSkipArg=script.replace(new RegExp("\\s*".concat(skipArg,"\\s*"),'g'),' ');if(!skipOnConflict){return withoutSkipArg;}return withoutSkipArg.replace("".concat(POSTHOG_REACT_NATIVE_XCODE_PATH," "),"".concat(POSTHOG_REACT_NATIVE_XCODE_PATH," ").concat(skipArg," "));}function addPostHogWithBundledScriptsToBundleShellScript(script){var skipOnConflict=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var postHogArgs=skipOnConflict?'--posthog-skip-on-conflict -- ':'';return script.replace(REACT_NATIVE_XCODE_LINE,function(_match,indent,rnCommand){return"".concat(indent,"/bin/sh ").concat(POSTHOG_REACT_NATIVE_XCODE_PATH," ").concat(postHogArgs).concat(rnCommand);});}var POSTHOG_DSYM_BUILD_PHASE_NAME='Upload Txlemetry Debug Symbols';function buildDsymUploadShellScript(){var includeSource=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var lines=['# Upload iOS dSYMs to Txlemetry so native crashes can be symbolicated.','# upload-symbols.sh ships inside the posthog-ios dependency.'];if(includeSource){lines.push('# Also upload native source files for source-code context around crashes.','export POSTHOG_INCLUDE_SOURCE=1');}lines.push('PODS_SCRIPT="${PODS_ROOT}/PostHog/build-tools/upload-symbols.sh"','SPM_SCRIPT="${BUILD_DIR%/Build/*}/SourcePackages/checkouts/posthog-ios/build-tools/upload-symbols.sh"','if [ -f "$PODS_SCRIPT" ]; then',' /bin/sh "$PODS_SCRIPT"','elif [ -f "$SPM_SCRIPT" ]; then',' /bin/sh "$SPM_SCRIPT"','else',' echo "warning: Txlemetry upload-symbols.sh not found in Pods or SwiftPM checkouts; skipping dSYM upload."','fi');return lines.join('\n');}function addDsymUploadBuildPhase(xcodeProject){var includeSource=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var existing=xcodeProject.pbxItemByComment(POSTHOG_DSYM_BUILD_PHASE_NAME,'PBXShellScriptBuildPhase');if(existing){return;}xcodeProject.addBuildPhase([],'PBXShellScriptBuildPhase',POSTHOG_DSYM_BUILD_PHASE_NAME,null,{shellPath:'/bin/sh',shellScript:buildDsymUploadShellScript(includeSource)});}function disableUserScriptSandboxing(xcodeProject){var configurations=xcodeProject.pbxXCBuildConfigurationSection();for(var key in configurations){var configuration=configurations[key];if(configuration&&configuration.buildSettings){configuration.buildSettings.ENABLE_USER_SCRIPT_SANDBOXING='"NO"';}}}function resolveNativeSymbolUpload(prop){if(prop===true){return{enabled:true,includeSource:false};}if(prop&&(0,_typeof2["default"])(prop)==='object'){return{enabled:true,includeSource:prop.includeSource===true};}return{enabled:false,includeSource:false};}var withIosPlugin=function withIosPlugin(config){var props=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return withXcodeProject(config,function(config){var xcodeProject=config.modResults;var bundleReactNativePhase=xcodeProject.pbxItemByComment('Bundle React Native code and images','PBXShellScriptBuildPhase');modifyExistingXcodeBuildScript(bundleReactNativePhase,props.skipOnConflict===true);var nativeSymbols=resolveNativeSymbolUpload(props.uploadNativeSymbols);if(nativeSymbols.enabled){addDsymUploadBuildPhase(xcodeProject,nativeSymbols.includeSource);}if(props.disableSandboxing!==false){disableUserScriptSandboxing(xcodeProject);console.warn('[txlemetry-react-native] Setting ENABLE_USER_SCRIPT_SANDBOXING=NO on all Xcode '+'build configurations so sourcemap uploads can resolve git metadata. '+'If your org requires sandboxing to stay enabled, set `{ disableSandboxing: false }` '+'on the plugin in app.json — note that stock Expo projects may fail to build under '+'sandboxing until every script build phase declares its input/output files.');}return config;});};var withPostHogPlugin=function withPostHogPlugin(config){var props=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};config=withAndroidPlugin(config,props.skipOnConflict===true);if(resolveNativeSymbolUpload(props.uploadNativeSymbols).enabled){config=withAndroidNativeSymbolsPlugin(config);}return withIosPlugin(config,props);};var postHogPlugin=function postHogPlugin(config){var props=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return withPostHogPlugin(config,props);};module.exports=postHogPlugin;module.exports.modifyExistingXcodeBuildScript=modifyExistingXcodeBuildScript;module.exports.addPostHogWithBundledScriptsToBundleShellScript=addPostHogWithBundledScriptsToBundleShellScript;module.exports.disableUserScriptSandboxing=disableUserScriptSandboxing;module.exports.buildDsymUploadShellScript=buildDsymUploadShellScript;module.exports.addDsymUploadBuildPhase=addDsymUploadBuildPhase;module.exports.resolveNativeSymbolUpload=resolveNativeSymbolUpload;module.exports.buildAndroidSkipOnConflictGradleLine=buildAndroidSkipOnConflictGradleLine;module.exports.addPostHogAndroidGradlePluginClasspath=addPostHogAndroidGradlePluginClasspath;module.exports.applyPostHogAndroidGradlePlugin=applyPostHogAndroidGradlePlugin;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { MetroConfig } from 'metro';
|
|
2
|
+
import type { DefaultConfigOptions } from './vendor/expo/expoconfig';
|
|
3
|
+
export * from './posthogMetroSerializer';
|
|
4
|
+
export interface PostHogMetroConfigOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Whether the plugin is enabled.
|
|
7
|
+
* Set to `false` to disable PostHog's Metro plugins (useful for local development).
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
enabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface PostHogExpoConfigOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Pass a custom `getDefaultConfig` function to override the default Expo configuration getter.
|
|
15
|
+
*/
|
|
16
|
+
getDefaultConfig?: (projectRoot: string, options?: Record<string, unknown>) => Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* This function returns Default Expo configuration with PostHog plugins.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getPostHogExpoConfig(projectRoot: string, options?: DefaultConfigOptions & PostHogExpoConfigOptions & PostHogMetroConfigOptions): MetroConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});var _exportNames={getPostHogExpoConfig:true};exports.getPostHogExpoConfig=getPostHogExpoConfig;var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _posthogMetroSerializer=require("./posthogMetroSerializer");Object.keys(_posthogMetroSerializer).forEach(function(key){if(key==="default"||key==="__esModule")return;if(Object.prototype.hasOwnProperty.call(_exportNames,key))return;if(key in exports&&exports[key]===_posthogMetroSerializer[key])return;Object.defineProperty(exports,key,{enumerable:true,get:function get(){return _posthogMetroSerializer[key];}});});function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable;})),t.push.apply(t,o);}return t;}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach(function(r){(0,_defineProperty2["default"])(e,r,t[r]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r));});}return e;}function getPostHogExpoConfig(projectRoot){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var _a;var enabled=(_a=options.enabled)!==null&&_a!==void 0?_a:true;var getDefaultConfig=options.getDefaultConfig||loadExpoMetroConfigModule().getDefaultConfig;if(!enabled){return getDefaultConfig(projectRoot,options);}var config=getDefaultConfig(projectRoot,_objectSpread(_objectSpread({},options),{},{unstable_beforeAssetSerializationPlugins:[].concat((0,_toConsumableArray2["default"])(options.unstable_beforeAssetSerializationPlugins||[]),[_posthogMetroSerializer.unstableBeforeAssetSerializationDebugIdPlugin])}));return config;}function loadExpoMetroConfigModule(){try{return require('expo/metro-config');}catch(e){throw new Error('Unable to load `expo/metro-config`. Make sure you have Expo installed.');}}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MixedOutput, Module, ReadOnlyGraph } from 'metro';
|
|
2
|
+
import type { MetroSerializer } from './utils';
|
|
3
|
+
/**
|
|
4
|
+
* Adds PostHog Chunk ID polyfill module to the bundle.
|
|
5
|
+
*/
|
|
6
|
+
export declare function unstableBeforeAssetSerializationDebugIdPlugin({ graph, premodules, debugId, }: {
|
|
7
|
+
graph: ReadOnlyGraph<MixedOutput>;
|
|
8
|
+
premodules: Module[];
|
|
9
|
+
debugId?: string;
|
|
10
|
+
}): Module[];
|
|
11
|
+
/**
|
|
12
|
+
* Creates a Metro serializer that adds Chunk ID module to the plain bundle.
|
|
13
|
+
* The Chunk ID module is a virtual module that provides a Chunk ID in runtime.
|
|
14
|
+
*
|
|
15
|
+
* RAM Bundles do not support custom serializers.
|
|
16
|
+
*/
|
|
17
|
+
export declare const createPostHogMetroSerializer: (customSerializer?: MetroSerializer) => MetroSerializer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.createPostHogMetroSerializer=void 0;exports.unstableBeforeAssetSerializationDebugIdPlugin=unstableBeforeAssetSerializationDebugIdPlugin;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _utils=require("./utils");var _utils2=require("./vendor/metro/utils");var DEBUG_ID_PLACE_HOLDER='__POSTHOG_CHUNK_ID__';var DEBUG_ID_MODULE_PATH='__chunkid__';var SOURCE_MAP_COMMENT='//# sourceMappingURL=';var DEBUG_ID_COMMENT='//# chunkId=';function unstableBeforeAssetSerializationDebugIdPlugin(_ref){var graph=_ref.graph,premodules=_ref.premodules,debugId=_ref.debugId;if(graph.transformOptions.platform==='web'){return premodules;}if(!debugId){return premodules;}var debugIdModuleExists=premodules.some(function(module){return module.path===DEBUG_ID_MODULE_PATH;});if(debugIdModuleExists){console.warn('\n\nChunk ID module found. Skipping Txlemetry Chunk ID module...\n\n');return premodules;}var debugIdModule=createDebugIdModule(debugId);return(0,_utils.prependModule)(premodules,debugIdModule);}var createPostHogMetroSerializer=exports.createPostHogMetroSerializer=function createPostHogMetroSerializer(customSerializer){var serializer=customSerializer||(0,_utils2.createDefaultMetroSerializer)();return function(){var _ref2=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(entryPoint,premodules,graph,options){var debugIdModuleExists,debugIdModule,modifiedPremodules,serializerResult,_yield$extractSeriali,bundleCode,bundleMapString,debugId,debugIdComment,indexOfSourceMapComment,bundleCodeWithDebugId,bundleMap;return _regenerator["default"].wrap(function(_context){while(1)switch(_context.prev=_context.next){case 0:if(!graph.transformOptions.hot){_context.next=1;break;}return _context.abrupt("return",serializer(entryPoint,premodules,graph,options));case 1:debugIdModuleExists=premodules.some(function(module){return module.path===DEBUG_ID_MODULE_PATH;});if(!debugIdModuleExists){_context.next=2;break;}console.warn('Chunk ID module found. Skipping Txlemetry Chunk ID module...');return _context.abrupt("return",serializer(entryPoint,premodules,graph,options));case 2:debugIdModule=createDebugIdModule(DEBUG_ID_PLACE_HOLDER);modifiedPremodules=(0,_utils.prependModule)(premodules,debugIdModule);serializerResult=serializer(entryPoint,modifiedPremodules,graph,options);_context.next=3;return extractSerializerResult(serializerResult);case 3:_yield$extractSeriali=_context.sent;bundleCode=_yield$extractSeriali.code;bundleMapString=_yield$extractSeriali.map;debugId=(0,_utils.determineDebugIdFromBundleSource)(bundleCode);if(debugId){_context.next=4;break;}throw new Error('Chunk ID was not found in the bundle.');case 4:console.log('info '+"Bundle Chunk ID: ".concat(debugId));debugIdComment="".concat(DEBUG_ID_COMMENT).concat(debugId);indexOfSourceMapComment=bundleCode.lastIndexOf(SOURCE_MAP_COMMENT);bundleCodeWithDebugId=indexOfSourceMapComment===-1?"".concat(bundleCode,"\n").concat(debugIdComment):"".concat(bundleCode.substring(0,indexOfSourceMapComment)+debugIdComment,"\n").concat(bundleCode.substring(indexOfSourceMapComment));bundleMap=JSON.parse(bundleMapString);bundleMap['chunkId']=debugId;return _context.abrupt("return",{code:bundleCodeWithDebugId,map:JSON.stringify(bundleMap)});case 5:case"end":return _context.stop();}},_callee);}));return function(_x,_x2,_x3,_x4){return _ref2.apply(this,arguments);};}();};function extractSerializerResult(_x5){return _extractSerializerResult.apply(this,arguments);}function _extractSerializerResult(){_extractSerializerResult=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee2(serializerResult){var awaitedResult;return _regenerator["default"].wrap(function(_context2){while(1)switch(_context2.prev=_context2.next){case 0:if(!(typeof serializerResult==='string')){_context2.next=1;break;}return _context2.abrupt("return",{code:serializerResult,map:'{}'});case 1:if(!('map'in serializerResult)){_context2.next=2;break;}return _context2.abrupt("return",{code:serializerResult.code,map:serializerResult.map});case 2:_context2.next=3;return serializerResult;case 3:awaitedResult=_context2.sent;if(!(typeof awaitedResult==='string')){_context2.next=4;break;}return _context2.abrupt("return",{code:awaitedResult,map:'{}'});case 4:return _context2.abrupt("return",{code:awaitedResult.code,map:awaitedResult.map});case 5:case"end":return _context2.stop();}},_callee2);}));return _extractSerializerResult.apply(this,arguments);}function createDebugIdModule(debugId){return(0,_utils.createVirtualJSModule)(DEBUG_ID_MODULE_PATH,(0,_utils.createDebugIdSnippet)(debugId));}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { MixedOutput, Module, ReadOnlyGraph, SerializerOptions } from 'metro';
|
|
2
|
+
import type CountingSet from 'metro/src/lib/CountingSet';
|
|
3
|
+
export type VirtualJSOutput = {
|
|
4
|
+
type: 'js/script/virtual';
|
|
5
|
+
data: {
|
|
6
|
+
code: string;
|
|
7
|
+
lineCount: number;
|
|
8
|
+
map: [];
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export type Bundle = {
|
|
12
|
+
modules: Array<[id: number, code: string]>;
|
|
13
|
+
post: string;
|
|
14
|
+
pre: string;
|
|
15
|
+
};
|
|
16
|
+
export type SerializedBundle = {
|
|
17
|
+
code: string;
|
|
18
|
+
map: string;
|
|
19
|
+
};
|
|
20
|
+
export type MetroSerializerOutput = string | SerializedBundle | Promise<string | SerializedBundle>;
|
|
21
|
+
export type MetroSerializer = (entryPoint: string, premodules: ReadonlyArray<Module>, graph: ReadOnlyGraph, options: SerializerOptions) => MetroSerializerOutput;
|
|
22
|
+
/**
|
|
23
|
+
* Returns minified Chunk ID code snippet.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createDebugIdSnippet(debugId: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Deterministically hashes a string and turns the hash into a uuid.
|
|
28
|
+
*
|
|
29
|
+
* https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/58271f1af2ade6b3e64d393d70376ae53bc5bd2f/packages/bundler-plugin-core/src/utils.ts#L174
|
|
30
|
+
*/
|
|
31
|
+
export declare function stringToUUID(str: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Looks for an injected `_posthogChunkIds[n] = "debugId"` pattern
|
|
34
|
+
* in the bundle source and extracts the `debugId` value from it.
|
|
35
|
+
*
|
|
36
|
+
* Matches both string and numeric keys for `n`, e.g.:
|
|
37
|
+
* _posthogChunkIds["abc"] = "1234"
|
|
38
|
+
* _posthogChunkIds[42] = "1234"
|
|
39
|
+
*/
|
|
40
|
+
export declare function determineDebugIdFromBundleSource(code: string): string | undefined;
|
|
41
|
+
export declare const createSet: () => CountingSet<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Prepends the module after default required prelude modules.
|
|
44
|
+
*/
|
|
45
|
+
export declare function prependModule(modules: readonly Module<MixedOutput>[], module: Module<VirtualJSOutput>): Module<MixedOutput>[];
|
|
46
|
+
/**
|
|
47
|
+
* Creates a virtual JS module with the given path and code.
|
|
48
|
+
*/
|
|
49
|
+
export declare function createVirtualJSModule(modulePath: string, moduleCode: string): Module<VirtualJSOutput> & {
|
|
50
|
+
setSource: (code: string) => void;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Tries to load Expo config using `@expo/config` package.
|
|
54
|
+
*/
|
|
55
|
+
export declare function getExpoConfig(projectRoot: string): Partial<{
|
|
56
|
+
name: string;
|
|
57
|
+
version: string;
|
|
58
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _typeof=require("@babel/runtime/helpers/typeof");Object.defineProperty(exports,"__esModule",{value:true});exports.createDebugIdSnippet=createDebugIdSnippet;exports.createSet=void 0;exports.createVirtualJSModule=createVirtualJSModule;exports.determineDebugIdFromBundleSource=determineDebugIdFromBundleSource;exports.getExpoConfig=getExpoConfig;exports.prependModule=prependModule;exports.stringToUUID=stringToUUID;var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var crypto=_interopRequireWildcard(require("crypto"));var _countLines=_interopRequireDefault(require("./vendor/metro/countLines"));function _interopRequireWildcard(e,t){if("function"==typeof WeakMap)var r=new WeakMap(),n=new WeakMap();return(_interopRequireWildcard=function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var o,i,f={__proto__:null,"default":e};if(null===e||"object"!=_typeof(e)&&"function"!=typeof e)return f;if(o=t?n:r){if(o.has(e))return o.get(e);o.set(e,f);}for(var _t2 in e)"default"!==_t2&&{}.hasOwnProperty.call(e,_t2)&&((i=(o=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,_t2))&&(i.get||i.set)?o(f,_t2,i):f[_t2]=e[_t2]);return f;})(e,t);}function createDebugIdSnippet(debugId){return"!function(){try{var e=\"undefined\"!=typeof window?window:\"undefined\"!=typeof global?global:\"undefined\"!=typeof globalThis?globalThis:\"undefined\"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._posthogChunkIds=e._posthogChunkIds||{},e._posthogChunkIds[n]=\"".concat(debugId,"\")}catch(e){}}();");}function stringToUUID(str){var md5sum=crypto.createHash('md5');md5sum.update(str);var md5Hash=md5sum.digest('hex');var v4variant=['8','9','a','b'][md5Hash.substring(16,17).charCodeAt(0)%4];return"".concat(md5Hash.substring(0,8),"-").concat(md5Hash.substring(8,12),"-4").concat(md5Hash.substring(13,16),"-").concat(v4variant).concat(md5Hash.substring(17,20),"-").concat(md5Hash.substring(20)).toLowerCase();}function determineDebugIdFromBundleSource(code){var match=code.match(/_posthogChunkIds\[\s*(?:(?:"[^"]*")|(?:'[^']*')|\d+)\s*\]\s*=\s*"([^"]+)"/);return match?match[1]:undefined;}function resolveSetCreator(){var CountingSetFromPrivate=safeRequireCountingSetFromPrivate();if(CountingSetFromPrivate){return function(){return new CountingSetFromPrivate["default"]();};}var CountingSetFromSrc=safeRequireCountingSetFromSrc();if(CountingSetFromSrc){return function(){return new CountingSetFromSrc["default"]();};}return function(){return new Set();};}function safeRequireCountingSetFromSrc(){try{return require('metro/src/lib/CountingSet');}catch(e){return undefined;}}function safeRequireCountingSetFromPrivate(){try{return require('metro/private/lib/CountingSet');}catch(e){return undefined;}}var createSet=exports.createSet=resolveSetCreator();var PRELUDE_MODULE_PATH='__prelude__';function prependModule(modules,module){var modifiedPremodules=(0,_toConsumableArray2["default"])(modules);if(modifiedPremodules.length>0&&modifiedPremodules[0]!==undefined&&modifiedPremodules[0].path===PRELUDE_MODULE_PATH){modifiedPremodules.unshift(modules[0]);modifiedPremodules[1]=module;}else{modifiedPremodules.unshift(module);}return modifiedPremodules;}function createVirtualJSModule(modulePath,moduleCode){var sourceCode=moduleCode;return{setSource:function setSource(code){sourceCode=code;},dependencies:new Map(),getSource:function getSource(){return Buffer.from(sourceCode);},inverseDependencies:createSet(),path:modulePath,output:[{type:'js/script/virtual',data:{code:sourceCode,lineCount:(0,_countLines["default"])(sourceCode),map:[]}}]};}function getExpoConfig(projectRoot){try{var expoConfig=require('@expo/config');if(expoConfig.getConfig){var _expoConfig$getConfig=expoConfig.getConfig(projectRoot),exp=_expoConfig$getConfig.exp;return{name:typeof exp.name==='string'&&exp.name?exp.name:undefined,version:typeof exp.version==='string'&&exp.version?exp.version:undefined};}}catch(_a){}return{};}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { MixedOutput, Module, ReadOnlyGraph } from 'metro';
|
|
2
|
+
export interface DefaultConfigOptions {
|
|
3
|
+
/** @deprecated */
|
|
4
|
+
mode?: 'exotic';
|
|
5
|
+
/**
|
|
6
|
+
* **Experimental:** Enable CSS support for Metro web, and shim on native.
|
|
7
|
+
*
|
|
8
|
+
* This is an experimental feature and may change in the future. The underlying implementation
|
|
9
|
+
* is subject to change, and native support for CSS Modules may be added in the future during a non-major SDK release.
|
|
10
|
+
*/
|
|
11
|
+
isCSSEnabled?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* **Experimental:** Modify premodules before a code asset is serialized
|
|
14
|
+
*
|
|
15
|
+
* This is an experimental feature and may change in the future. The underlying implementation
|
|
16
|
+
* is subject to change.
|
|
17
|
+
*/
|
|
18
|
+
unstable_beforeAssetSerializationPlugins?: ((serializationInput: {
|
|
19
|
+
graph: ReadOnlyGraph<MixedOutput>;
|
|
20
|
+
premodules: Module[];
|
|
21
|
+
debugId?: string;
|
|
22
|
+
}) => Module[])[];
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports["default"]=void 0;var newline=/\r\n?|\n|\u2028|\u2029/g;var _default=exports["default"]=function _default(string){return(string.match(newline)||[]).length+1;};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Module, ReadOnlyGraph } from 'metro';
|
|
2
|
+
import type { MetroSerializer } from '../../utils';
|
|
3
|
+
/**
|
|
4
|
+
* This function ensures that modules in source maps are sorted in the same
|
|
5
|
+
* order as in a plain JS bundle.
|
|
6
|
+
*
|
|
7
|
+
* https://github.com/facebook/metro/blob/9b85f83c9cc837d8cd897aa7723be7da5b296067/packages/metro/src/Server.js#L984
|
|
8
|
+
*/
|
|
9
|
+
export declare const getSortedModules: (graph: ReadOnlyGraph, { createModuleId, }: {
|
|
10
|
+
createModuleId: (file: string) => number;
|
|
11
|
+
}) => readonly Module[];
|
|
12
|
+
/**
|
|
13
|
+
* Creates the default Metro plain bundle serializer.
|
|
14
|
+
* Because Metro exports only the intermediate serializer functions, we need to
|
|
15
|
+
* assemble the final serializer ourselves. We have to work with the modules the same as Metro does
|
|
16
|
+
* to avoid unexpected changes in the final bundle.
|
|
17
|
+
*
|
|
18
|
+
* This is used when the user does not provide a custom serializer.
|
|
19
|
+
*
|
|
20
|
+
* https://github.com/facebook/metro/blob/9b85f83c9cc837d8cd897aa7723be7da5b296067/packages/metro/src/Server.js#L244-L277
|
|
21
|
+
*/
|
|
22
|
+
export declare const createDefaultMetroSerializer: () => MetroSerializer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.getSortedModules=exports.createDefaultMetroSerializer=void 0;var _typeof2=_interopRequireDefault(require("@babel/runtime/helpers/typeof"));var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _a,_b;var baseJSBundleModule;try{baseJSBundleModule=require('metro/private/DeltaBundler/Serializers/baseJSBundle');}catch(_c){baseJSBundleModule=require('metro/src/DeltaBundler/Serializers/baseJSBundle');}var baseJSBundle=typeof baseJSBundleModule==='function'?baseJSBundleModule:(_a=baseJSBundleModule===null||baseJSBundleModule===void 0?void 0:baseJSBundleModule.baseJSBundle)!==null&&_a!==void 0?_a:baseJSBundleModule===null||baseJSBundleModule===void 0?void 0:baseJSBundleModule["default"];var sourceMapString;try{var sourceMapStringModule=require('metro/private/DeltaBundler/Serializers/sourceMapString');sourceMapString=sourceMapStringModule.sourceMapString;}catch(e){sourceMapString=require('metro/src/DeltaBundler/Serializers/sourceMapString');if('sourceMapString'in sourceMapString){sourceMapString=sourceMapString.sourceMapString;}}var bundleToStringModule;try{bundleToStringModule=require('metro/private/lib/bundleToString');}catch(_d){bundleToStringModule=require('metro/src/lib/bundleToString');}var bundleToString=typeof bundleToStringModule==='function'?bundleToStringModule:(_b=bundleToStringModule===null||bundleToStringModule===void 0?void 0:bundleToStringModule.bundleToString)!==null&&_b!==void 0?_b:bundleToStringModule===null||bundleToStringModule===void 0?void 0:bundleToStringModule["default"];var getSortedModules=exports.getSortedModules=function getSortedModules(graph,_ref){var createModuleId=_ref.createModuleId;var modules=(0,_toConsumableArray2["default"])(graph.dependencies.values());return modules.sort(function(a,b){return createModuleId(a.path)-createModuleId(b.path);});};var createDefaultMetroSerializer=exports.createDefaultMetroSerializer=function createDefaultMetroSerializer(){return function(entryPoint,premodules,graph,options){var bundle=(baseJSBundle["default"]||baseJSBundle)(entryPoint,premodules,graph,options);var _ref2=(bundleToString["default"]||bundleToString)(bundle),code=_ref2.code;if(graph.transformOptions.hot){return code;}var sourceMapStringFunction;if(typeof sourceMapString==='function'){sourceMapStringFunction=sourceMapString;}else if((0,_typeof2["default"])(sourceMapString)==='object'&&sourceMapString!=null&&'sourceMapString'in sourceMapString&&typeof sourceMapString['sourceMapString']==='function'){sourceMapStringFunction=sourceMapString.sourceMapString;}else{throw new Error("\n[txlemetry-react-native/metro] Can't find sourceMapString function in 'metro/src/DeltaBundler/Serializers/sourceMapString'.\nPlease check the version of Metro you are using and report the issue at https://github.com/postHog/posthog-js\n");}var map=(sourceMapStringFunction["default"]||sourceMapStringFunction)([].concat((0,_toConsumableArray2["default"])(premodules),(0,_toConsumableArray2["default"])(getSortedModules(graph,options))),{processModuleFilter:options.processModuleFilter,shouldAddToIgnoreList:options.shouldAddToIgnoreList||function(){return false;}});return{code:code,map:map};};};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
export type PostHogAutocaptureNavigationTrackerOptions = {
|
|
2
|
+
routeToName?: (name: string, params: any) => string;
|
|
3
|
+
routeToProperties?: (name: string, params: any) => Record<string, any>;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated
|
|
7
|
+
*/
|
|
8
|
+
export type PostHogNavigationRef = {
|
|
9
|
+
getCurrentRoute(): any | undefined;
|
|
10
|
+
isReady: () => boolean;
|
|
11
|
+
current?: PostHogNavigationRef | any | undefined;
|
|
12
|
+
};
|
|
13
|
+
export type PostHogAutocaptureOptions = {
|
|
14
|
+
/**
|
|
15
|
+
* Enable autocapture of touch events
|
|
16
|
+
*
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
captureTouches?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Custom prop name used to label elements for autocapture
|
|
22
|
+
*
|
|
23
|
+
* @default 'ph-label'
|
|
24
|
+
*/
|
|
25
|
+
customLabelProp?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Prop name used to prevent autocapture on an element and its children
|
|
28
|
+
*
|
|
29
|
+
* @default 'ph-no-capture'
|
|
30
|
+
*/
|
|
31
|
+
noCaptureProp?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Maximum number of elements to capture in the component tree hierarchy
|
|
34
|
+
*
|
|
35
|
+
* @default 20
|
|
36
|
+
*/
|
|
37
|
+
maxElementsCaptured?: number;
|
|
38
|
+
/**
|
|
39
|
+
* List of element labels to ignore during autocapture
|
|
40
|
+
*
|
|
41
|
+
* @default []
|
|
42
|
+
*/
|
|
43
|
+
ignoreLabels?: string[];
|
|
44
|
+
/**
|
|
45
|
+
* List of prop names to capture from elements
|
|
46
|
+
*
|
|
47
|
+
* @default ['style', 'testID', 'accessibilityLabel', 'ph-label', 'children']
|
|
48
|
+
*/
|
|
49
|
+
propsToCapture?: string[];
|
|
50
|
+
/**
|
|
51
|
+
* Capture the screen name (or route name) and properties
|
|
52
|
+
*
|
|
53
|
+
* Only used for expo-router, @react-navigation/native and react-native-navigation
|
|
54
|
+
*
|
|
55
|
+
* For react-native-navigation, you need to call initReactNativeNavigation before using this option
|
|
56
|
+
* See example: https://posthog.com/docs/libraries/react-native#with-react-native-navigation-and-autocapture
|
|
57
|
+
*
|
|
58
|
+
* For @react-navigation/native v6 and below, you need to wrap the PostHogProvider within the NavigationContainer
|
|
59
|
+
* See example: https://posthog.com/docs/libraries/react-native#with-react-navigationnative-and-autocapture
|
|
60
|
+
*
|
|
61
|
+
* For @react-navigation/native v7 and above, because of a library change, you'll need to capture the screens manually and disable this option
|
|
62
|
+
* You can use the onStateChange callback from the NavigationContainer to capture the screens automatically using the screen capture method
|
|
63
|
+
* You can use the 'usePostHog()' hook or your own posthog instance to capture the screens
|
|
64
|
+
* Since captureScreens is disabled, you don't need to pass the navigationRef, the navigation mutation object is also ignored
|
|
65
|
+
* See example: https://reactnavigation.org/docs/screen-tracking/ and https://posthog.com/docs/libraries/react-native#manually-capturing-screen-capture-events
|
|
66
|
+
*
|
|
67
|
+
* For expo-router, expo-router uses @react-navigation/native, but does not expose the NavigationContainer, you'll need to capture the screens manually and disable this option
|
|
68
|
+
* expo-router always has access to a URL, you can use the URL to capture the screens automatically using the screen capture method
|
|
69
|
+
* You can use the 'usePostHog()' hook or your own posthog instance to capture the screens
|
|
70
|
+
* Since captureScreens is disabled, you don't need to pass the navigationRef, the navigation mutation object is also ignored
|
|
71
|
+
* See example: https://docs.expo.dev/router/reference/screen-tracking/ and https://posthog.com/docs/libraries/react-native#manually-capturing-screen-capture-events
|
|
72
|
+
*
|
|
73
|
+
* @default true
|
|
74
|
+
*/
|
|
75
|
+
captureScreens?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Used for mutating the screen name and properties
|
|
78
|
+
* Only used if captureScreens is true
|
|
79
|
+
*
|
|
80
|
+
* @default Default to the route name and params
|
|
81
|
+
*/
|
|
82
|
+
navigation?: PostHogAutocaptureNavigationTrackerOptions;
|
|
83
|
+
/**
|
|
84
|
+
* If you create a navigation ref with createNavigationContainerRef, you need to pass the navigation ref
|
|
85
|
+
* Only used for expo-router and @react-navigation/native if captureScreens is true
|
|
86
|
+
*
|
|
87
|
+
* @deprecated this is deprecated since it didn't work as expected, check out the `captureScreens` comments for capturing screen views semi-automatically
|
|
88
|
+
*/
|
|
89
|
+
navigationRef?: PostHogNavigationRef;
|
|
90
|
+
};
|
|
91
|
+
export interface PostHogCustomAppProperties {
|
|
92
|
+
/** Build number like "1.2.2" or "122" */
|
|
93
|
+
$app_build?: string | null;
|
|
94
|
+
/** Name of the app as displayed below the icon like "PostHog" */
|
|
95
|
+
$app_name?: string | null;
|
|
96
|
+
/** Namespace of the app usually like "com.posthog.app" */
|
|
97
|
+
$app_namespace?: string | null;
|
|
98
|
+
/** Human friendly app version like what a user would see in the app store like "1.2.2" */
|
|
99
|
+
$app_version?: string | null;
|
|
100
|
+
/** Manufacturer like "Apple", "Samsung" or "Android" */
|
|
101
|
+
$device_manufacturer?: string | null;
|
|
102
|
+
/** Readable model name like "iPhone 12" or "Samsung Galaxy S24" */
|
|
103
|
+
$device_name?: string | null;
|
|
104
|
+
/** Model identifier like "iPhone13,2" or "SM-S921B" */
|
|
105
|
+
$device_model?: string | null;
|
|
106
|
+
/** Device type ("Mobile" | "Desktop") */
|
|
107
|
+
$device_type?: string | null;
|
|
108
|
+
/** Operating system name like iOS or Android */
|
|
109
|
+
$os_name?: string | null;
|
|
110
|
+
/** Operating system version "14.0" */
|
|
111
|
+
$os_version?: string | null;
|
|
112
|
+
/** Locale (language) of the device like "en-US" */
|
|
113
|
+
$locale?: string | null;
|
|
114
|
+
/** Timezone of the device like "Europe/Berlin" */
|
|
115
|
+
$timezone?: string | null;
|
|
116
|
+
/** Whether the app is running on an emulator/simulator */
|
|
117
|
+
$is_emulator?: boolean | null;
|
|
118
|
+
}
|
|
119
|
+
export type PostHogSessionReplayConfig = {
|
|
120
|
+
/**
|
|
121
|
+
* Enable masking of all text and text input fields
|
|
122
|
+
*
|
|
123
|
+
* @default true
|
|
124
|
+
*/
|
|
125
|
+
maskAllTextInputs?: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Enable masking of all images to a placeholder
|
|
128
|
+
*
|
|
129
|
+
* @default true
|
|
130
|
+
*/
|
|
131
|
+
maskAllImages?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Enable masking of all sandboxed system views
|
|
134
|
+
* These may include UIImagePickerController, PHPickerViewController and CNContactPickerViewController
|
|
135
|
+
* iOS only
|
|
136
|
+
*
|
|
137
|
+
* @default true
|
|
138
|
+
*/
|
|
139
|
+
maskAllSandboxedViews?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Enable capturing of logs as console events
|
|
142
|
+
*
|
|
143
|
+
* @default true
|
|
144
|
+
*/
|
|
145
|
+
captureLog?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Deboucer delay used to reduce the number of snapshots captured and reduce performance impact
|
|
148
|
+
* This is used for capturing the view as a screenshot
|
|
149
|
+
* The lower the number more snapshots will be captured but higher the performance impact
|
|
150
|
+
*
|
|
151
|
+
* @default 1000
|
|
152
|
+
* @deprecated please use throttleDelayMs instead
|
|
153
|
+
*/
|
|
154
|
+
iOSdebouncerDelayMs?: number;
|
|
155
|
+
/**
|
|
156
|
+
* Deboucer delay used to reduce the number of snapshots captured and reduce performance impact
|
|
157
|
+
* This is used for capturing the view as a screenshot
|
|
158
|
+
* The lower the number more snapshots will be captured but higher the performance impact
|
|
159
|
+
* Ps: it was 500ms (0.5s) by default until version 3.3.7
|
|
160
|
+
*
|
|
161
|
+
* @default 1000
|
|
162
|
+
* @deprecated please use throttleDelayMs instead
|
|
163
|
+
*/
|
|
164
|
+
androidDebouncerDelayMs?: number;
|
|
165
|
+
/**
|
|
166
|
+
* Throttling delay used to reduce the number of snapshots captured and reduce performance impact
|
|
167
|
+
* This is used for capturing the view as a wireframe or screenshot
|
|
168
|
+
* The lower the number more snapshots will be captured but higher the performance impact
|
|
169
|
+
*
|
|
170
|
+
* This value has precedence over iOSdebouncerDelayMs and androidDebouncerDelayMs
|
|
171
|
+
* If this is not set, we will take the max number between iOSdebouncerDelayMs and androidDebouncerDelayMs for back compatibility
|
|
172
|
+
*
|
|
173
|
+
* @default 1000
|
|
174
|
+
*/
|
|
175
|
+
throttleDelayMs?: number;
|
|
176
|
+
/**
|
|
177
|
+
* Enable capturing network telemetry
|
|
178
|
+
* iOS only
|
|
179
|
+
*
|
|
180
|
+
* @default true
|
|
181
|
+
*/
|
|
182
|
+
captureNetworkTelemetry?: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Schedule screenshot image capture on a background queue.
|
|
185
|
+
* iOS only
|
|
186
|
+
* Experimental support
|
|
187
|
+
*
|
|
188
|
+
* Warning: Enabling this option will trigger Main Thread Checker warnings and may
|
|
189
|
+
* briefly freeze the app the first time a screenshot is captured. Consider disabling
|
|
190
|
+
* Main Thread Checker in your scheme's run diagnostics when enabling this.
|
|
191
|
+
*
|
|
192
|
+
* @default false
|
|
193
|
+
*/
|
|
194
|
+
screenshotModeBackgroundCapture?: boolean;
|
|
195
|
+
/**
|
|
196
|
+
* Session replay sample rate between 0 and 1
|
|
197
|
+
* Local config has precedence over remote config when both are set.
|
|
198
|
+
* If undefined, sampling is controlled by remote config (when available).
|
|
199
|
+
*/
|
|
200
|
+
sampleRate?: number;
|
|
201
|
+
};
|
|
202
|
+
export interface PostHogCustomStorage {
|
|
203
|
+
getItem: (key: string) => string | null | Promise<string | null>;
|
|
204
|
+
setItem: (key: string, value: string) => void | Promise<void>;
|
|
205
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { getRemoteConfigBool, getRemoteConfigNumber, isValidSampleRate } from '@txlemetry/core';
|
|
2
|
+
type ReactNativeGlobal = {
|
|
3
|
+
HermesInternal?: {
|
|
4
|
+
enablePromiseRejectionTracker?: (args: {
|
|
5
|
+
allRejections: boolean;
|
|
6
|
+
onUnhandled?: (id: string, error: any) => void;
|
|
7
|
+
onHandled?: (id: string, error: any) => void;
|
|
8
|
+
}) => void;
|
|
9
|
+
hasPromise?: () => boolean;
|
|
10
|
+
};
|
|
11
|
+
ErrorUtils?: {
|
|
12
|
+
getGlobalHandler?: () => (error: Error, isFatal: boolean) => void;
|
|
13
|
+
setGlobalHandler?: (handler: (error: Error, isFatal: boolean) => void) => void;
|
|
14
|
+
};
|
|
15
|
+
onunhandledrejection?: (event: unknown) => void;
|
|
16
|
+
};
|
|
17
|
+
export declare const GLOBAL_OBJ: ReactNativeGlobal;
|
|
18
|
+
export declare function getPlatformOS(): string | undefined;
|
|
19
|
+
/** Checks if the current platform is web */
|
|
20
|
+
export declare function isWeb(): boolean;
|
|
21
|
+
/** Checks if the current platform is macOS */
|
|
22
|
+
export declare function isMacOS(): boolean;
|
|
23
|
+
/** Checks if the current platform is Windows */
|
|
24
|
+
export declare function isWindows(): boolean;
|
|
25
|
+
export declare const isHermes: () => boolean;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.GLOBAL_OBJ=void 0;exports.getPlatformOS=getPlatformOS;Object.defineProperty(exports,"getRemoteConfigBool",{enumerable:true,get:function get(){return _core.getRemoteConfigBool;}});Object.defineProperty(exports,"getRemoteConfigNumber",{enumerable:true,get:function get(){return _core.getRemoteConfigNumber;}});exports.isHermes=void 0;exports.isMacOS=isMacOS;Object.defineProperty(exports,"isValidSampleRate",{enumerable:true,get:function get(){return _core.isValidSampleRate;}});exports.isWeb=isWeb;exports.isWindows=isWindows;var _reactNative=require("react-native");var _core=require("@txlemetry/core");var _global=typeof global!=='undefined'?global:undefined;var _globalThis=typeof globalThis!=='undefined'?globalThis:undefined;var GLOBAL_OBJ=exports.GLOBAL_OBJ=_globalThis!==null&&_globalThis!==void 0?_globalThis:_global;function getPlatformOS(){try{return _reactNative.Platform===null||_reactNative.Platform===void 0?void 0:_reactNative.Platform.OS;}catch(_a){return undefined;}}function isWeb(){return getPlatformOS()==='web';}function isMacOS(){return getPlatformOS()==='macos';}function isWindows(){return getPlatformOS()==='windows';}var isHermes=exports.isHermes=function isHermes(){return!!GLOBAL_OBJ.HermesInternal;};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "4.55.0";
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.version=void 0;var version=exports.version="4.55.0";
|