txlemetry-react-native 4.55.1 → 5.0.0
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 -353
- package/dist/TxlemetryContext.d.ts +5 -0
- package/dist/TxlemetryContext.js +1 -0
- package/dist/TxlemetryErrorBoundary.d.ts +27 -0
- package/dist/TxlemetryErrorBoundary.js +1 -0
- package/dist/{PostHogMaskView.d.ts → TxlemetryMaskView.d.ts} +39 -39
- package/dist/TxlemetryMaskView.js +1 -0
- package/dist/TxlemetryProvider.d.ts +100 -0
- package/dist/TxlemetryProvider.js +1 -0
- package/dist/autocapture.d.ts +4 -4
- package/dist/autocapture.js +1 -1
- package/dist/error-tracking/index.d.ts +98 -98
- package/dist/error-tracking/index.js +1 -1
- package/dist/error-tracking/utils.d.ts +5 -5
- package/dist/frameworks/wix-navigation.d.ts +3 -3
- package/dist/frameworks/wix-navigation.js +1 -1
- package/dist/hooks/useFeatureFlag.d.ts +5 -5
- package/dist/hooks/useFeatureFlag.js +1 -1
- package/dist/hooks/useFeatureFlagResult.d.ts +3 -3
- package/dist/hooks/useFeatureFlagResult.js +1 -1
- package/dist/hooks/useFeatureFlags.d.ts +3 -3
- package/dist/hooks/useFeatureFlags.js +1 -1
- package/dist/hooks/useNavigationTracker.d.ts +6 -6
- package/dist/hooks/useNavigationTracker.js +1 -1
- package/dist/hooks/useTxlemetry.d.ts +2 -0
- package/dist/hooks/useTxlemetry.js +1 -0
- package/dist/hooks/utils.d.ts +14 -14
- package/dist/hooks/utils.js +1 -1
- package/dist/index.d.ts +14 -14
- package/dist/index.js +1 -1
- package/dist/index.txlemetry.d.ts +36 -36
- package/dist/index.txlemetry.js +21 -21
- package/dist/logs-defaults.d.ts +9 -9
- package/dist/native-deps.d.ts +4 -4
- package/dist/native-deps.js +1 -1
- package/dist/optional/OptionalAsyncStorage.d.ts +2 -2
- package/dist/optional/OptionalExpoApplication.d.ts +2 -2
- package/dist/optional/OptionalExpoDevice.d.ts +2 -2
- package/dist/optional/OptionalExpoFileSystem.d.ts +2 -2
- package/dist/optional/OptionalExpoFileSystemLegacy.d.ts +2 -2
- package/dist/optional/OptionalExpoLocalization.d.ts +2 -2
- package/dist/optional/OptionalPlugin.d.ts +20 -20
- package/dist/optional/OptionalReactNativeDeviceInfo.d.ts +2 -2
- package/dist/optional/OptionalReactNativeLocalize.d.ts +13 -13
- package/dist/optional/OptionalReactNativeNavigation.d.ts +2 -2
- package/dist/optional/OptionalReactNativeNavigationWix.d.ts +2 -2
- package/dist/optional/OptionalReactNativeSafeArea.d.ts +2 -2
- package/dist/optional/OptionalReactNativeSvg.d.ts +2 -2
- package/dist/storage.d.ts +41 -41
- package/dist/storage.js +1 -1
- package/dist/surveys/{PostHogSurveyProvider.d.ts → TxlemetrySurveyProvider.d.ts} +23 -23
- package/dist/surveys/TxlemetrySurveyProvider.js +1 -0
- package/dist/surveys/components/BottomSection.d.ts +9 -9
- package/dist/surveys/components/BottomSection.js +1 -1
- package/dist/surveys/components/Cancel.d.ts +5 -5
- package/dist/surveys/components/Cancel.js +1 -1
- package/dist/surveys/components/ConfirmationMessage.d.ts +12 -12
- package/dist/surveys/components/ConfirmationMessage.js +1 -1
- package/dist/surveys/components/QuestionHeader.d.ts +8 -8
- package/dist/surveys/components/QuestionHeader.js +1 -1
- package/dist/surveys/components/QuestionTypes.d.ts +26 -26
- package/dist/surveys/components/QuestionTypes.js +1 -1
- package/dist/surveys/components/SurveyModal.d.ts +11 -11
- package/dist/surveys/components/SurveyModal.js +1 -1
- package/dist/surveys/components/Surveys.d.ts +16 -16
- package/dist/surveys/components/Surveys.js +1 -1
- package/dist/surveys/getActiveMatchingSurveys.d.ts +2 -2
- package/dist/surveys/icons.d.ts +11 -11
- package/dist/surveys/icons.js +1 -1
- package/dist/surveys/index.d.ts +6 -6
- package/dist/surveys/index.js +1 -1
- package/dist/surveys/safeStyleSheet.d.ts +8 -8
- package/dist/surveys/survey-translations.d.ts +7 -7
- package/dist/surveys/survey-translations.js +1 -1
- package/dist/surveys/surveys-utils.d.ts +54 -54
- package/dist/surveys/surveys-utils.js +1 -1
- package/dist/surveys/useActivatedSurveys.d.ts +3 -3
- package/dist/surveys/useActivatedSurveys.js +1 -1
- package/dist/surveys/useSurveyStorage.d.ts +8 -8
- package/dist/surveys/useSurveyStorage.js +1 -1
- package/dist/tooling/expoconfig.d.ts +64 -64
- package/dist/tooling/expoconfig.js +1 -1
- package/dist/tooling/metroconfig.d.ts +21 -21
- package/dist/tooling/metroconfig.js +1 -1
- package/dist/tooling/{posthogMetroSerializer.d.ts → txlemetryMetroSerializer.d.ts} +17 -17
- package/dist/tooling/txlemetryMetroSerializer.js +1 -0
- package/dist/tooling/utils.d.ts +58 -58
- package/dist/tooling/vendor/expo/expoconfig.d.ts +23 -23
- package/dist/tooling/vendor/metro/countLines.d.ts +2 -2
- package/dist/tooling/vendor/metro/utils.d.ts +22 -22
- package/dist/{posthog-rn.d.ts → txlemetry-rn.d.ts} +1096 -1096
- package/dist/txlemetry-rn.js +1 -0
- package/dist/types.d.ts +205 -205
- package/dist/utils.d.ts +25 -25
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +149 -149
- package/tooling/txlemetry-xcode.sh +2 -2
- package/dist/PostHogContext.d.ts +0 -5
- package/dist/PostHogContext.js +0 -1
- package/dist/PostHogErrorBoundary.d.ts +0 -27
- package/dist/PostHogErrorBoundary.js +0 -1
- package/dist/PostHogMaskView.js +0 -1
- package/dist/PostHogProvider.d.ts +0 -100
- package/dist/PostHogProvider.js +0 -1
- package/dist/hooks/usePostHog.d.ts +0 -2
- package/dist/hooks/usePostHog.js +0 -1
- package/dist/posthog-rn.js +0 -1
- package/dist/surveys/PostHogSurveyProvider.js +0 -1
- package/dist/tooling/posthogMetroSerializer.js +0 -1
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { Survey, SurveyQuestion, SurveyQuestionBranchingType, MultipleSurveyQuestion, SurveyAppearance, SurveyQuestionDescriptionContentType, SurveyMatchType } from '@txlemetry/core';
|
|
2
|
-
export type PropertyOperator = SurveyMatchType | 'gt' | 'lt';
|
|
3
|
-
export type PropertyFilters = {
|
|
4
|
-
[propertyName: string]: {
|
|
5
|
-
values: string[];
|
|
6
|
-
operator: PropertyOperator;
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
export interface SurveyEventWithFilters {
|
|
10
|
-
name: string;
|
|
11
|
-
propertyFilters?: PropertyFilters;
|
|
12
|
-
}
|
|
13
|
-
export declare const isMatchingRegex: (value: string, pattern: string) => boolean;
|
|
14
|
-
export declare const surveyValidationMap: Record<PropertyOperator, (targets: string[], values: string[]) => boolean>;
|
|
15
|
-
export declare function matchPropertyFilters(propertyFilters: PropertyFilters | undefined, eventProperties: Record<string, unknown> | undefined): boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Utility function to determine if a description should be rendered based on content type
|
|
18
|
-
* Only renders text content, skips HTML content for React Native compatibility
|
|
19
|
-
* Defaults to Text content type when not specified
|
|
20
|
-
* @param description The description text
|
|
21
|
-
* @param contentType The content type (text or html), defaults to Text if not provided
|
|
22
|
-
* @returns True if the description should be rendered, false otherwise
|
|
23
|
-
*/
|
|
24
|
-
export declare function shouldRenderDescription(description?: string | null, contentType?: SurveyQuestionDescriptionContentType): boolean;
|
|
25
|
-
export declare const defaultBackgroundColor: "#eeeded";
|
|
26
|
-
export declare const defaultDescriptionOpacity = 0.8;
|
|
27
|
-
export declare const defaultRatingLabelOpacity = 0.7;
|
|
28
|
-
export type SurveyAppearanceTheme = Omit<Required<SurveyAppearance>, 'widgetSelector' | 'widgetType' | 'widgetColor' | 'widgetLabel' | 'shuffleQuestions' | 'textColor' | 'inputTextColor'> & {
|
|
29
|
-
textColor?: string;
|
|
30
|
-
inputTextColor?: string;
|
|
31
|
-
};
|
|
32
|
-
export declare const defaultSurveyAppearance: SurveyAppearanceTheme;
|
|
33
|
-
export type SurveyFlexAlign = 'flex-start' | 'center' | 'flex-end';
|
|
34
|
-
export declare function resolveSurveyAlignment(position: string | undefined): {
|
|
35
|
-
vertical: SurveyFlexAlign;
|
|
36
|
-
horizontal: SurveyFlexAlign;
|
|
37
|
-
};
|
|
38
|
-
export declare const getDisplayOrderQuestions: (survey: Survey) => SurveyQuestion[];
|
|
39
|
-
export declare const hasEvents: (survey: Survey) => boolean;
|
|
40
|
-
export declare const canActivateRepeatedly: (survey: Survey) => boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Use the Fisher-yates algorithm to shuffle this array
|
|
43
|
-
* https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
|
|
44
|
-
*/
|
|
45
|
-
export declare const getDisplayOrderChoices: (question: MultipleSurveyQuestion) => string[];
|
|
46
|
-
/**
|
|
47
|
-
* Determines the next question to show based on the survey's branching logic
|
|
48
|
-
* @param survey The survey object
|
|
49
|
-
* @param currentQuestionIndex The current question index
|
|
50
|
-
* @param response The user's response to the current question
|
|
51
|
-
* @returns The index of the next question or SurveyQuestionBranchingType.End if the survey should end
|
|
52
|
-
*/
|
|
53
|
-
export declare function getNextSurveyStep(survey: Survey, currentQuestionIndex: number, response: string | string[] | number | null): number | typeof SurveyQuestionBranchingType.End;
|
|
54
|
-
export declare function getContrastingTextColor(color: string): 'black' | 'white';
|
|
1
|
+
import { Survey, SurveyQuestion, SurveyQuestionBranchingType, MultipleSurveyQuestion, SurveyAppearance, SurveyQuestionDescriptionContentType, SurveyMatchType } from '@txlemetry/core';
|
|
2
|
+
export type PropertyOperator = SurveyMatchType | 'gt' | 'lt';
|
|
3
|
+
export type PropertyFilters = {
|
|
4
|
+
[propertyName: string]: {
|
|
5
|
+
values: string[];
|
|
6
|
+
operator: PropertyOperator;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export interface SurveyEventWithFilters {
|
|
10
|
+
name: string;
|
|
11
|
+
propertyFilters?: PropertyFilters;
|
|
12
|
+
}
|
|
13
|
+
export declare const isMatchingRegex: (value: string, pattern: string) => boolean;
|
|
14
|
+
export declare const surveyValidationMap: Record<PropertyOperator, (targets: string[], values: string[]) => boolean>;
|
|
15
|
+
export declare function matchPropertyFilters(propertyFilters: PropertyFilters | undefined, eventProperties: Record<string, unknown> | undefined): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Utility function to determine if a description should be rendered based on content type
|
|
18
|
+
* Only renders text content, skips HTML content for React Native compatibility
|
|
19
|
+
* Defaults to Text content type when not specified
|
|
20
|
+
* @param description The description text
|
|
21
|
+
* @param contentType The content type (text or html), defaults to Text if not provided
|
|
22
|
+
* @returns True if the description should be rendered, false otherwise
|
|
23
|
+
*/
|
|
24
|
+
export declare function shouldRenderDescription(description?: string | null, contentType?: SurveyQuestionDescriptionContentType): boolean;
|
|
25
|
+
export declare const defaultBackgroundColor: "#eeeded";
|
|
26
|
+
export declare const defaultDescriptionOpacity = 0.8;
|
|
27
|
+
export declare const defaultRatingLabelOpacity = 0.7;
|
|
28
|
+
export type SurveyAppearanceTheme = Omit<Required<SurveyAppearance>, 'widgetSelector' | 'widgetType' | 'widgetColor' | 'widgetLabel' | 'shuffleQuestions' | 'textColor' | 'inputTextColor'> & {
|
|
29
|
+
textColor?: string;
|
|
30
|
+
inputTextColor?: string;
|
|
31
|
+
};
|
|
32
|
+
export declare const defaultSurveyAppearance: SurveyAppearanceTheme;
|
|
33
|
+
export type SurveyFlexAlign = 'flex-start' | 'center' | 'flex-end';
|
|
34
|
+
export declare function resolveSurveyAlignment(position: string | undefined): {
|
|
35
|
+
vertical: SurveyFlexAlign;
|
|
36
|
+
horizontal: SurveyFlexAlign;
|
|
37
|
+
};
|
|
38
|
+
export declare const getDisplayOrderQuestions: (survey: Survey) => SurveyQuestion[];
|
|
39
|
+
export declare const hasEvents: (survey: Survey) => boolean;
|
|
40
|
+
export declare const canActivateRepeatedly: (survey: Survey) => boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Use the Fisher-yates algorithm to shuffle this array
|
|
43
|
+
* https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
|
|
44
|
+
*/
|
|
45
|
+
export declare const getDisplayOrderChoices: (question: MultipleSurveyQuestion) => string[];
|
|
46
|
+
/**
|
|
47
|
+
* Determines the next question to show based on the survey's branching logic
|
|
48
|
+
* @param survey The survey object
|
|
49
|
+
* @param currentQuestionIndex The current question index
|
|
50
|
+
* @param response The user's response to the current question
|
|
51
|
+
* @returns The index of the next question or SurveyQuestionBranchingType.End if the survey should end
|
|
52
|
+
*/
|
|
53
|
+
export declare function getNextSurveyStep(survey: Survey, currentQuestionIndex: number, response: string | string[] | number | null): number | typeof SurveyQuestionBranchingType.End;
|
|
54
|
+
export declare function getContrastingTextColor(color: string): 'black' | 'white';
|
|
@@ -1 +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()];}
|
|
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("[Txlemetry.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()];}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Survey } from '@txlemetry/core';
|
|
2
|
-
import {
|
|
3
|
-
export declare function useActivatedSurveys(
|
|
1
|
+
import { Survey } from '@txlemetry/core';
|
|
2
|
+
import { Txlemetry } from '../txlemetry-rn';
|
|
3
|
+
export declare function useActivatedSurveys(txlemetry: Txlemetry, surveys: Survey[]): ReadonlySet<string>;
|
|
@@ -1 +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(
|
|
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(txlemetry,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 txlemetry.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,txlemetry]);return activatedSurveys;}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
type SurveyStorage = {
|
|
2
|
-
seenSurveys: string[];
|
|
3
|
-
setSeenSurvey: (surveyId: string) => void;
|
|
4
|
-
lastSeenSurveyDate: Date | undefined;
|
|
5
|
-
setLastSeenSurveyDate: (date: Date) => void;
|
|
6
|
-
};
|
|
7
|
-
export declare function useSurveyStorage(): SurveyStorage;
|
|
8
|
-
export {};
|
|
1
|
+
type SurveyStorage = {
|
|
2
|
+
seenSurveys: string[];
|
|
3
|
+
setSeenSurvey: (surveyId: string) => void;
|
|
4
|
+
lastSeenSurveyDate: Date | undefined;
|
|
5
|
+
setLastSeenSurveyDate: (date: Date) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare function useSurveyStorage(): SurveyStorage;
|
|
8
|
+
export {};
|
|
@@ -1 +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
|
|
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 _useTxlemetry=require("../hooks/useTxlemetry");function useSurveyStorage(){var txlemetryStorage=(0,_useTxlemetry.useTxlemetry)();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(){txlemetryStorage.ready().then(function(){var lastSeenSurveyDate=txlemetryStorage.getPersistedProperty(_core.TxlemetryPersistedProperty.SurveyLastSeenDate);if(typeof lastSeenSurveyDate==='string'){setLastSeenSurveyDate(new Date(lastSeenSurveyDate));}var serialisedSeenSurveys=txlemetryStorage.getPersistedProperty(_core.TxlemetryPersistedProperty.SurveysSeen);if(typeof serialisedSeenSurveys==='string'){var parsedSeenSurveys=JSON.parse(serialisedSeenSurveys);if(Array.isArray(parsedSeenSurveys)&&typeof parsedSeenSurveys[0]==='string'){setSeenSurveys(parsedSeenSurveys);}}});},[txlemetryStorage]);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;})));txlemetryStorage.setPersistedProperty(_core.TxlemetryPersistedProperty.SurveysSeen,JSON.stringify(newValue.slice(0,20)));return newValue;});},[txlemetryStorage]),lastSeenSurveyDate:lastSeenSurveyDate,setLastSeenSurveyDate:(0,_react.useCallback)(function(date){setLastSeenSurveyDate(date);txlemetryStorage.setPersistedProperty(_core.TxlemetryPersistedProperty.SurveyLastSeenDate,date.toISOString());},[txlemetryStorage])};}
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
export declare function buildAndroidSkipOnConflictGradleLine(skipOnConflict: boolean): string | null;
|
|
2
|
-
export declare function
|
|
3
|
-
contents: string;
|
|
4
|
-
classpathPresent: boolean;
|
|
5
|
-
};
|
|
6
|
-
export declare function
|
|
7
|
-
type BuildPhase = {
|
|
8
|
-
shellScript: string;
|
|
9
|
-
};
|
|
10
|
-
export declare function modifyExistingXcodeBuildScript(script: BuildPhase, skipOnConflict?: boolean): void;
|
|
11
|
-
export declare function
|
|
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
|
|
16
|
-
/**
|
|
17
|
-
* Whether to disable Xcode's user script sandboxing (ENABLE_USER_SCRIPT_SANDBOXING=NO).
|
|
18
|
-
*
|
|
19
|
-
*
|
|
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
|
|
36
|
-
* - iOS: a build phase that runs
|
|
37
|
-
* (`
|
|
38
|
-
* - Android: the official `com.
|
|
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
|
|
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
|
|
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 `
|
|
49
|
-
*/
|
|
50
|
-
uploadNativeSymbols?: boolean | {
|
|
51
|
-
includeSource?: boolean;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Whether to append `--skip-on-conflict` to `
|
|
55
|
-
*
|
|
56
|
-
* Default: false.
|
|
57
|
-
*/
|
|
58
|
-
skipOnConflict?: boolean;
|
|
59
|
-
};
|
|
60
|
-
export declare function resolveNativeSymbolUpload(prop:
|
|
61
|
-
enabled: boolean;
|
|
62
|
-
includeSource: boolean;
|
|
63
|
-
};
|
|
64
|
-
export {};
|
|
1
|
+
export declare function buildAndroidSkipOnConflictGradleLine(skipOnConflict: boolean): string | null;
|
|
2
|
+
export declare function addTxlemetryAndroidGradlePluginClasspath(projectBuildGradle: string): {
|
|
3
|
+
contents: string;
|
|
4
|
+
classpathPresent: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare function applyTxlemetryAndroidGradlePlugin(appBuildGradle: string): string;
|
|
7
|
+
type BuildPhase = {
|
|
8
|
+
shellScript: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function modifyExistingXcodeBuildScript(script: BuildPhase, skipOnConflict?: boolean): void;
|
|
11
|
+
export declare function addTxlemetryWithBundledScriptsToBundleShellScript(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 TxlemetryPluginProps = {
|
|
16
|
+
/**
|
|
17
|
+
* Whether to disable Xcode's user script sandboxing (ENABLE_USER_SCRIPT_SANDBOXING=NO).
|
|
18
|
+
*
|
|
19
|
+
* txlemetry-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 Txlemetry SDKs already ship:
|
|
36
|
+
* - iOS: a build phase that runs txlemetry-ios's `upload-symbols.sh`
|
|
37
|
+
* (`txlemetry-cli dsym upload`).
|
|
38
|
+
* - Android: the official `com.txlemetry.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 Txlemetry
|
|
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 Txlemetry, 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 `txlemetry-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 `txlemetry-cli hermes upload` on iOS and Android.
|
|
55
|
+
*
|
|
56
|
+
* Default: false.
|
|
57
|
+
*/
|
|
58
|
+
skipOnConflict?: boolean;
|
|
59
|
+
};
|
|
60
|
+
export declare function resolveNativeSymbolUpload(prop: TxlemetryPluginProps['uploadNativeSymbols']): {
|
|
61
|
+
enabled: boolean;
|
|
62
|
+
includeSource: boolean;
|
|
63
|
+
};
|
|
64
|
+
export {};
|
|
@@ -1 +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;
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.addDsymUploadBuildPhase=addDsymUploadBuildPhase;exports.addTxlemetryAndroidGradlePluginClasspath=addTxlemetryAndroidGradlePluginClasspath;exports.addTxlemetryWithBundledScriptsToBundleShellScript=addTxlemetryWithBundledScriptsToBundleShellScript;exports.applyTxlemetryAndroidGradlePlugin=applyTxlemetryAndroidGradlePlugin;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 TXLEMETRY_ANDROID_GRADLE_PLUGIN_VERSION="2.0.0";var resolveTxlemetryReactNativePackageJsonPath="[\"node\", \"--print\", \"require('path').join(require('path').dirname(require.resolve('txlemetry-react-native')), '..', 'tooling', 'txlemetry.gradle')\"].execute().text.trim()";var TXLEMETRY_ANDROID_SKIP_ON_CONFLICT_PROPERTY="txlemetryReactNativeSkipOnConflict";function buildAndroidSkipOnConflictGradleLine(skipOnConflict){if(!skipOnConflict){return null;}return"project.ext.".concat(TXLEMETRY_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(resolveTxlemetryReactNativePackageJsonPath,")");var skipOnConflictLine=buildAndroidSkipOnConflictGradleLine(skipOnConflict);var applyBlock=skipOnConflictLine?"".concat(skipOnConflictLine,"\n").concat(applyFrom):applyFrom;var skipOnConflictPattern=new RegExp("^project\\.ext\\.".concat(TXLEMETRY_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('Txlemetry: 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 addTxlemetryAndroidGradlePluginClasspath(projectBuildGradle){if(projectBuildGradle.includes('txlemetry-android-gradle-plugin')){return{contents:projectBuildGradle,classpathPresent:true};}var classpathLine=" classpath(\"com.txlemetry:txlemetry-android-gradle-plugin:".concat(TXLEMETRY_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('Txlemetry: Could not find a buildscript dependencies block in the project build.gradle; '+"skipping the com.txlemetry.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 applyTxlemetryAndroidGradlePlugin(appBuildGradle){if(/apply plugin: ["']com.txlemetry.android["']/.test(appBuildGradle)){return appBuildGradle;}var applyLine="apply plugin: \"com.txlemetry.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('Txlemetry: Could not find where to apply com.txlemetry.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=addTxlemetryAndroidGradlePluginClasspath(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=applyTxlemetryAndroidGradlePlugin(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(updateTxlemetrySkipOnConflictArg(_code,skipOnConflict));return;}if(script.shellScript.includes('txlemetry-react-native')){return;}var code=JSON.parse(script.shellScript);script.shellScript=JSON.stringify(addTxlemetryWithBundledScriptsToBundleShellScript(code,skipOnConflict));}var TXLEMETRY_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 updateTxlemetrySkipOnConflictArg(script,skipOnConflict){var skipArg='--txlemetry-skip-on-conflict --';var legacySkipArg='--posthog-skip-on-conflict --';var withoutSkipArg=script.replace(new RegExp("\\s*(?:".concat(skipArg,"|").concat(legacySkipArg,")\\s*"),'g'),' ');if(!skipOnConflict){return withoutSkipArg;}return withoutSkipArg.replace("".concat(TXLEMETRY_REACT_NATIVE_XCODE_PATH," "),"".concat(TXLEMETRY_REACT_NATIVE_XCODE_PATH," ").concat(skipArg," "));}function addTxlemetryWithBundledScriptsToBundleShellScript(script){var skipOnConflict=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var txlemetryArgs=skipOnConflict?'--txlemetry-skip-on-conflict -- ':'';return script.replace(REACT_NATIVE_XCODE_LINE,function(_match,indent,rnCommand){return"".concat(indent,"/bin/sh ").concat(TXLEMETRY_REACT_NATIVE_XCODE_PATH," ").concat(txlemetryArgs).concat(rnCommand);});}var TXLEMETRY_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 txlemetry-ios dependency.'];if(includeSource){lines.push('# Also upload native source files for source-code context around crashes.','export TXLEMETRY_INCLUDE_SOURCE=1');}lines.push('PODS_SCRIPT="${PODS_ROOT}/Txlemetry/build-tools/upload-symbols.sh"',"SPM_SCRIPT=\"${BUILD_DIR%/Build/*}/SourcePackages/checkouts/txlemetry-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(TXLEMETRY_DSYM_BUILD_PHASE_NAME,'PBXShellScriptBuildPhase');if(existing){return;}xcodeProject.addBuildPhase([],'PBXShellScriptBuildPhase',TXLEMETRY_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 withTxlemetryPlugin=function withTxlemetryPlugin(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 txlemetryPlugin=function txlemetryPlugin(config){var props=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return withTxlemetryPlugin(config,props);};module.exports=txlemetryPlugin;module.exports.modifyExistingXcodeBuildScript=modifyExistingXcodeBuildScript;module.exports.addTxlemetryWithBundledScriptsToBundleShellScript=addTxlemetryWithBundledScriptsToBundleShellScript;module.exports.disableUserScriptSandboxing=disableUserScriptSandboxing;module.exports.buildDsymUploadShellScript=buildDsymUploadShellScript;module.exports.addDsymUploadBuildPhase=addDsymUploadBuildPhase;module.exports.resolveNativeSymbolUpload=resolveNativeSymbolUpload;module.exports.buildAndroidSkipOnConflictGradleLine=buildAndroidSkipOnConflictGradleLine;module.exports.addTxlemetryAndroidGradlePluginClasspath=addTxlemetryAndroidGradlePluginClasspath;module.exports.applyTxlemetryAndroidGradlePlugin=applyTxlemetryAndroidGradlePlugin;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import type { MetroConfig } from 'metro';
|
|
2
|
-
import type { DefaultConfigOptions } from './vendor/expo/expoconfig';
|
|
3
|
-
export * from './
|
|
4
|
-
export interface
|
|
5
|
-
/**
|
|
6
|
-
* Whether the plugin is enabled.
|
|
7
|
-
* Set to `false` to disable
|
|
8
|
-
* @default true
|
|
9
|
-
*/
|
|
10
|
-
enabled?: boolean;
|
|
11
|
-
}
|
|
12
|
-
export interface
|
|
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
|
|
20
|
-
*/
|
|
21
|
-
export declare function
|
|
1
|
+
import type { MetroConfig } from 'metro';
|
|
2
|
+
import type { DefaultConfigOptions } from './vendor/expo/expoconfig';
|
|
3
|
+
export * from './txlemetryMetroSerializer';
|
|
4
|
+
export interface TxlemetryMetroConfigOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Whether the plugin is enabled.
|
|
7
|
+
* Set to `false` to disable Txlemetry's Metro plugins (useful for local development).
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
enabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface TxlemetryExpoConfigOptions {
|
|
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 Txlemetry plugins.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getTxlemetryExpoConfig(projectRoot: string, options?: DefaultConfigOptions & TxlemetryExpoConfigOptions & TxlemetryMetroConfigOptions): MetroConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});var _exportNames={
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});var _exportNames={getTxlemetryExpoConfig:true};exports.getTxlemetryExpoConfig=getTxlemetryExpoConfig;var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _txlemetryMetroSerializer=require("./txlemetryMetroSerializer");Object.keys(_txlemetryMetroSerializer).forEach(function(key){if(key==="default"||key==="__esModule")return;if(Object.prototype.hasOwnProperty.call(_exportNames,key))return;if(key in exports&&exports[key]===_txlemetryMetroSerializer[key])return;Object.defineProperty(exports,key,{enumerable:true,get:function get(){return _txlemetryMetroSerializer[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 getTxlemetryExpoConfig(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||[]),[_txlemetryMetroSerializer.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.');}}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type { MixedOutput, Module, ReadOnlyGraph } from 'metro';
|
|
2
|
-
import type { MetroSerializer } from './utils';
|
|
3
|
-
/**
|
|
4
|
-
* Adds
|
|
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
|
|
1
|
+
import type { MixedOutput, Module, ReadOnlyGraph } from 'metro';
|
|
2
|
+
import type { MetroSerializer } from './utils';
|
|
3
|
+
/**
|
|
4
|
+
* Adds Txlemetry 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 createTxlemetryMetroSerializer: (customSerializer?: MetroSerializer) => MetroSerializer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.createTxlemetryMetroSerializer=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 createTxlemetryMetroSerializer=exports.createTxlemetryMetroSerializer=function createTxlemetryMetroSerializer(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));}
|