Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENGG-1567 ENGG-1568] MV3: auto migration of rules #1669

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e950f9e
migrate rules when importing
nafees87n May 4, 2024
32957ac
added path operator
nafees87n May 4, 2024
ad4c0f0
fix: rule migration
nafees87n May 4, 2024
7b633cd
Merge branch 'master' of github.com:requestly/requestly into ENGG-1567
nafees87n May 4, 2024
8cc124e
fix: func
nafees87n May 4, 2024
1bed163
addded extension updated path
nafees87n May 6, 2024
c4a887a
Merge branch 'master' of github.com:requestly/requestly into ENGG-1567
nafees87n May 6, 2024
b6642bc
fix: typo
nafees87n May 6, 2024
944bb24
added MV3MigrationState to storage
nafees87n May 6, 2024
edec9cc
changed query string
nafees87n May 7, 2024
53ac0ac
removed path from MV3
nafees87n May 7, 2024
9ca18e0
fix
nafees87n May 7, 2024
2a80246
fix: MV3 utils
nafees87n May 7, 2024
02b4c0f
added pageUrl migration
nafees87n May 7, 2024
87ed41f
added migration for page URL
nafees87n May 7, 2024
bb8e551
fix: workspace actions
nafees87n May 8, 2024
603c167
store migration data in local storage
nafees87n May 8, 2024
4d7bfa7
added enum
nafees87n May 8, 2024
9c83f77
fix:
nafees87n May 8, 2024
b299a0d
Merge branch 'master' of github.com:requestly/requestly into ENGG-1567
nafees87n May 8, 2024
4a3faf0
fix: unused variable
nafees87n May 8, 2024
2236a7a
refactor rules migration
nafees87n May 9, 2024
8f5b29c
refactor: variable name
nafees87n May 9, 2024
794fdf0
fix: workspace ID and keys
nafees87n May 9, 2024
8ef03a6
refractor mv3 migrations
wrongsahil May 9, 2024
3686e71
added sourceFilters change
nafees87n May 10, 2024
0fc88d4
fix: syncing issues
nafees87n May 13, 2024
844eca9
fix:
nafees87n May 13, 2024
f465249
remove MV3 unsupported features from UI
nafees87n May 13, 2024
a012ab9
Merge branch 'master' of github.com:requestly/requestly into ENGG-1567
nafees87n May 13, 2024
0797e53
added v3 migrations
wrongsahil May 13, 2024
2c829f0
migrations improvement
wrongsahil May 13, 2024
cd981df
added isFirstSyncComplete
wrongsahil May 13, 2024
4caed62
remove HeadersRuleV1
wrongsahil May 13, 2024
5dde643
headers_v2 deprecate
wrongsahil May 13, 2024
5f646f2
backward compatibilty path url filter mv2
wrongsahil May 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
132 changes: 89 additions & 43 deletions app/src/components/features/rules/RulePairs/Filters/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import {
trackRequestMethodFilterModifiedEvent,
trackRequestPayloadKeyFilterModifiedEvent,
trackRequestPayloadValueFilterModifiedEvent,
trackPageDomainsFilterModifiedEvent,
} from "modules/analytics/events/common/rules/filters";
import { setCurrentlySelectedRule } from "../../RuleBuilder/actions";
import { ResponseRuleResourceType } from "types/rules";
import { debounce, snakeCase } from "lodash";
import { actions } from "store";
import { isExtensionManifestVersion3 } from "actions/ExtensionActions";

const { Text, Link } = Typography;

Expand Down Expand Up @@ -149,6 +151,10 @@ const Filters = (props) => {
LOG_ANALYTICS.PAGE_URL_MODIFIED = () => {
trackPageUrlFilterModifiedEvent(currentlySelectedRuleData.ruleType);
};

LOG_ANALYTICS.PAGE_DOMAINS_MODIFIED = () => {
trackPageDomainsFilterModifiedEvent(currentlySelectedRuleData.ruleType);
};
LOG_ANALYTICS.RESOURCE_TYPE_MODIFIED = () => {
trackResourceTypeFilterModifiedEvent(currentlySelectedRuleData.ruleType);
};
Expand Down Expand Up @@ -350,49 +356,89 @@ const Filters = (props) => {
alignItems: "center",
}}
>
<Col span={3}>
<span>Page URL</span>
</Col>
<Col span={6} align="center">
<Dropdown overlay={urlOperatorOptions} disabled={props.isInputDisabled}>
<Text
strong
className="ant-dropdown-link cursor-pointer capitalize uppercase"
onClick={(e) => {
e.preventDefault();
LOG_ANALYTICS.PAGE_URL_MODIFIED(e);
}}
>
{getCurrentPageURLOperatorText()} <DownOutlined />
</Text>
</Dropdown>
</Col>
<Col span={12}>
<Input
placeholder={generatePlaceholderText(
getObjectValue(
currentlySelectedRuleData,
pairIndex,
APP_CONSTANTS.PATH_FROM_PAIR.SOURCE_PAGE_URL_OPERATOR
)
)}
name="description"
type="text"
value={getObjectValue(
currentlySelectedRuleData,
pairIndex,
APP_CONSTANTS.PATH_FROM_PAIR.SOURCE_PAGE_URL_VALUE
)}
onChange={(e) => {
e?.preventDefault?.();
updateSourceRequestPayload(e, APP_CONSTANTS.PATH_FROM_PAIR.SOURCE_PAGE_URL_VALUE);
LOG_ANALYTICS.PAGE_URL_MODIFIED();
}}
disabled={getCurrentPageURLOperatorText() === "Select" ? true : props.isInputDisabled}
/>
</Col>
<Col align="right" span={3}>
{renderClearFilterIcon(GLOBAL_CONSTANTS.RULE_SOURCE_FILTER_TYPES.PAGE_URL)}
{isExtensionManifestVersion3() ? (
<>
<Col span={5}>
<span>Page Domain</span>
</Col>
<Col span={17}>
<Input
placeholder={"mydomain.com"}
name="description"
type="text"
value={getObjectValue(
currentlySelectedRuleData,
pairIndex,
APP_CONSTANTS.PATH_FROM_PAIR.SOURCE_PAGE_DOMAINS
)}
onChange={(e) => {
e?.preventDefault?.();
dispatch(
actions.updateRulePairAtGivenPath({
pairIndex,
updates: {
[APP_CONSTANTS.PATH_FROM_PAIR.SOURCE_PAGE_DOMAINS]: [e.target.value],
},
})
);
LOG_ANALYTICS.PAGE_DOMAINS_MODIFIED();
}}
disabled={props.isInputDisabled}
/>
</Col>
</>
) : (
<>
<Col span={3}>
<span>Page URL</span>
</Col>
<Col span={6} align="center">
<Dropdown overlay={urlOperatorOptions} disabled={props.isInputDisabled}>
<Text
strong
className="ant-dropdown-link cursor-pointer capitalize uppercase"
onClick={(e) => {
e.preventDefault();
LOG_ANALYTICS.PAGE_URL_MODIFIED(e);
}}
>
{getCurrentPageURLOperatorText()} <DownOutlined />
</Text>
</Dropdown>
</Col>
<Col span={12}>
<Input
placeholder={generatePlaceholderText(
getObjectValue(
currentlySelectedRuleData,
pairIndex,
APP_CONSTANTS.PATH_FROM_PAIR.SOURCE_PAGE_URL_OPERATOR
)
)}
name="description"
type="text"
value={getObjectValue(
currentlySelectedRuleData,
pairIndex,
APP_CONSTANTS.PATH_FROM_PAIR.SOURCE_PAGE_URL_VALUE
)}
onChange={(e) => {
e?.preventDefault?.();
updateSourceRequestPayload(e, APP_CONSTANTS.PATH_FROM_PAIR.SOURCE_PAGE_URL_VALUE);
LOG_ANALYTICS.PAGE_URL_MODIFIED();
}}
disabled={getCurrentPageURLOperatorText() === "Select" ? true : props.isInputDisabled}
/>
</Col>
</>
)}

<Col align="right" span={2}>
{renderClearFilterIcon(
isExtensionManifestVersion3()
? GLOBAL_CONSTANTS.RULE_SOURCE_FILTER_TYPES.PAGE_DOMAINS
: GLOBAL_CONSTANTS.RULE_SOURCE_FILTER_TYPES.PAGE_URL
)}
</Col>
</Row>
) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from "modules/analytics/events/features/testUrlModal";
import { trackRuleFilterModalToggled } from "modules/analytics/events/common/rules/filters";
import "./RequestSourceRow.css";
import { isExtensionManifestVersion3 } from "actions/ExtensionActions";

const { Text } = Typography;

Expand Down Expand Up @@ -126,23 +127,28 @@ const RequestSourceRow = ({ rowIndex, pair, pairIndex, ruleDetails, isInputDisab
const renderSourceKeys = useMemo(() => {
return (
<Menu>
{sourceKeys.map(({ id, title, ruleKey }) => (
<Menu.Item
key={id}
onClick={(event) => {
dispatch(
actions.updateRulePairAtGivenPath({
pairIndex,
updates: {
[APP_CONSTANTS.PATH_FROM_PAIR.RULE_KEYS]: ruleKey,
},
})
);
}}
>
{title}
</Menu.Item>
))}
{sourceKeys.map(({ id, title, ruleKey }) => {
if (isExtensionManifestVersion3() && ruleKey === GLOBAL_CONSTANTS.RULE_KEYS.PATH) {
return null;
}
wrongsahil marked this conversation as resolved.
Show resolved Hide resolved
return (
<Menu.Item
key={id}
onClick={(event) => {
dispatch(
actions.updateRulePairAtGivenPath({
pairIndex,
updates: {
[APP_CONSTANTS.PATH_FROM_PAIR.RULE_KEYS]: ruleKey,
},
})
);
}}
>
{title}
</Menu.Item>
);
})}
</Menu>
);
}, [dispatch, sourceKeys, pairIndex]);
Expand Down
1 change: 1 addition & 0 deletions app/src/config/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ APP_CONSTANTS.PATH_FROM_PAIR = {
SOURCE_REQUEST_PAYLOAD_KEY: "source.filters.requestPayload.key",
SOURCE_REQUEST_PAYLOAD_OPERATOR: "source.filters.requestPayload.operator",
SOURCE_REQUEST_PAYLOAD_VALUE: "source.filters.requestPayload.value",
SOURCE_PAGE_DOMAINS: "source.filters.pageDomains",
};

APP_CONSTANTS.GA_EVENTS = GA_EVENTS;
Expand Down
4 changes: 4 additions & 0 deletions app/src/config/constants/sub/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,10 @@ PATHS.EXTENSION_INSTALLED = {};
PATHS.EXTENSION_INSTALLED.RELATIVE = "/extension-installed";
PATHS.EXTENSION_INSTALLED.ABSOLUTE = joinPaths(PATHS.LANDING, PATHS.EXTENSION_INSTALLED.RELATIVE);

PATHS.EXTENSION_UPDATED = {};
PATHS.EXTENSION_UPDATED.RELATIVE = "/extension-updated";
PATHS.EXTENSION_UPDATED.ABSOLUTE = joinPaths(PATHS.LANDING, PATHS.EXTENSION_UPDATED.RELATIVE);

// Mock Server V2
PATHS.MOCK_SERVER_V2 = {};
PATHS.MOCK_SERVER_V2.INDEX = "apis";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Logger from "lib/logger";
import { runRuleMigrations } from "utils/rules/ruleMigrations";
import APP_CONSTANTS from "config/constants";
import { RecordStatus } from "features/rules";
import { isExtensionManifestVersion3 } from "actions/ExtensionActions";
import { migrateRuleToMV3 } from "modules/extension/utils";
//CONSTANTS
const { RULES_LIST_TABLE_CONSTANTS } = APP_CONSTANTS;

Expand Down Expand Up @@ -78,9 +80,14 @@ const setUnknownGroupIdsToUngroupped = (rulesArray, groupsIdObject) => {

export const processDataToImport = (incomingArray, user, allRules, overwrite = true) => {
const data = filterRulesAndGroups(incomingArray);
const rules = runRuleMigrations(data.rules.filter((object) => isObjectValid(object)));

let rules = runRuleMigrations(data.rules.filter((object) => isObjectValid(object)));
const groups = data.groups.filter((object) => isObjectValid(object));

if (isExtensionManifestVersion3()) {
rules = rules.map((rule) => migrateRuleToMV3(rule));
}

if (!overwrite) {
setNewIdofRules(rules);
setNewIdOfRulePairs(rules);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ import { StorageService } from "init";
import { useDispatch } from "react-redux";
import { isGroupsSanitizationPassed } from "components/features/rules/RulesIndexPage/actions";
import { recordsActions } from "store/features/rules/slice";
import { Group, Rule, RecordStatus, RecordType } from "features/rules/types/rules";
import { Group, RecordStatus, RecordType, Rule } from "features/rules/types/rules";
import { submitAttrUtil } from "utils/AnalyticsUtils";
import APP_CONSTANTS from "config/constants";
import { PREMIUM_RULE_TYPES } from "features/rules/constants";
import Logger from "../../../../../../../../../common/logger";
import { trackRulesListLoaded } from "features/rules/analytics";
import { isExtensionManifestVersion3 } from "actions/ExtensionActions";
import { getCurrentlyActiveWorkspace } from "store/features/teams/selectors";
import {
detectAndGenerateMV3RulesMigrationData,
getMV3MigrationData,
migrateRuleToMV3,
saveMV3MigrationData,
} from "modules/extension/utils";

const TRACKING = APP_CONSTANTS.GA_EVENTS;

Expand All @@ -23,6 +31,8 @@ const useFetchAndUpdateRules = ({ setIsLoading }: Props) => {
const appMode = useSelector(getAppMode);
const isRulesListRefreshPending = useSelector(getIsRefreshRulesPending);
const isRulesListHardRefreshPending = useSelector(getIsHardRefreshRulesPending);
const activeWorkspace = useSelector(getCurrentlyActiveWorkspace);

const hasIsRulesListRefreshPendingChanged = useHasChanged(isRulesListRefreshPending);
const hasIsRulesListHardRefreshPendingChanged = useHasChanged(isRulesListHardRefreshPending);

Expand All @@ -43,7 +53,38 @@ const useFetchAndUpdateRules = ({ setIsLoading }: Props) => {
Promise.all([groupsPromise, rulesPromise])
.then(async (data) => {
const groups = data[0] as Group[];
const rules = data[1] as Rule[];
let rules = data[1] as Rule[];

try {
if (isExtensionManifestVersion3()) {
const currentWorkspaceId = activeWorkspace?.id ?? "private";
const mv3MigrationData = getMV3MigrationData();

if (!mv3MigrationData?.[currentWorkspaceId]?.rulesMigrated) {
//TODO: rules types are not standardized. Need to standardize them

//@ts-ignore
const rulesMigrationData = detectAndGenerateMV3RulesMigrationData(rules, currentWorkspaceId);

//@ts-ignore
rules = rules.map((rule) => migrateRuleToMV3(rule));

StorageService(appMode)
.saveMultipleRulesOrGroups(rules, { workspaceId: activeWorkspace.id })
.then(() => {
saveMV3MigrationData({
...mv3MigrationData,
[currentWorkspaceId]: {
rulesMigrated: true,
rulesMigrationData: rulesMigrationData,
},
});
});
}
nafees87n marked this conversation as resolved.
Show resolved Hide resolved
}
} catch (e) {
console.error("DBG: Error in migrating rules to MV3", e);
}

Logger.log("DBG: fetched data", JSON.stringify({ rules, groups }));

Expand Down Expand Up @@ -91,6 +132,7 @@ const useFetchAndUpdateRules = ({ setIsLoading }: Props) => {
appMode,
hasIsRulesListRefreshPendingChanged,
hasIsRulesListHardRefreshPendingChanged,
activeWorkspace.id,
]);
};

Expand Down
4 changes: 4 additions & 0 deletions app/src/modules/analytics/events/common/rules/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export const trackPageUrlFilterModifiedEvent = (rule_type) => {
trackRuleFilterModified("page_url", rule_type);
};

export const trackPageDomainsFilterModifiedEvent = (rule_type) => {
trackRuleFilterModified("page_domains", rule_type);
};

export const trackResourceTypeFilterModifiedEvent = (rule_type) => {
trackRuleFilterModified("resource_type", rule_type);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ReplaceRule } from "../../../types/rules";
import { BLACKLISTED_DOMAINS } from "../constants";
import { ExtensionRule, RuleActionType } from "../types";
import { parseConditionFromSource } from "./utils";

Expand All @@ -10,18 +9,20 @@ const parseReplaceRule = (rule: ReplaceRule): ExtensionRule[] => {

rule.pairs.forEach((rulePair, pairIndex) => {
if (!rulePair.source.value) {
extensionRules.push({
const ruleCondition = {
condition: {
regexFilter: `(.*)${rulePair.from}(.*)`,
excludedRequestDomains: BLACKLISTED_DOMAINS,
...parseConditionFromSource(rulePair.source),
},
action: {
type: RuleActionType.REDIRECT,
redirect: {
regexSubstitution: `\\1${rulePair.to}\\2`,
},
},
});
};
delete ruleCondition.condition.urlFilter;
wrongsahil marked this conversation as resolved.
Show resolved Hide resolved
extensionRules.push(ruleCondition);
return;
}

Expand Down