|
| 1 | +import type { DeprecatedPrivacyOptions, ReplayIntegrationPrivacyOptions } from '../types'; |
| 2 | + |
| 3 | +type GetPrivacyOptions = Required<Omit<ReplayIntegrationPrivacyOptions, 'maskFn'>> & DeprecatedPrivacyOptions; |
| 4 | +interface GetPrivacyReturn { |
| 5 | + maskTextSelector: string; |
| 6 | + unmaskTextSelector: string; |
| 7 | + maskInputSelector: string; |
| 8 | + unmaskInputSelector: string; |
| 9 | + blockSelector: string; |
| 10 | + unblockSelector: string; |
| 11 | + ignoreSelector: string; |
| 12 | + |
| 13 | + blockClass?: RegExp; |
| 14 | + maskTextClass?: RegExp; |
| 15 | +} |
| 16 | + |
| 17 | +function getOption( |
| 18 | + selectors: string[], |
| 19 | + defaultSelectors: string[], |
| 20 | + deprecatedClassOption?: string | RegExp, |
| 21 | + deprecatedSelectorOption?: string, |
| 22 | +): string { |
| 23 | + const deprecatedSelectors = typeof deprecatedSelectorOption === 'string' ? deprecatedSelectorOption.split(',') : []; |
| 24 | + |
| 25 | + const allSelectors = [ |
| 26 | + ...selectors, |
| 27 | + // @deprecated |
| 28 | + ...deprecatedSelectors, |
| 29 | + |
| 30 | + // sentry defaults |
| 31 | + ...defaultSelectors, |
| 32 | + ]; |
| 33 | + |
| 34 | + // @deprecated |
| 35 | + if (typeof deprecatedClassOption !== 'undefined') { |
| 36 | + // NOTE: No support for RegExp |
| 37 | + if (typeof deprecatedClassOption === 'string') { |
| 38 | + allSelectors.push(`.${deprecatedClassOption}`); |
| 39 | + } |
| 40 | + |
| 41 | + // eslint-disable-next-line no-console |
| 42 | + console.warn( |
| 43 | + '[Replay] You are using a deprecated configuration item for privacy. Read the documentation on how to use the new privacy configuration.', |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + return allSelectors.join(','); |
| 48 | +} |
| 49 | + |
| 50 | +/** |
| 51 | + * Returns privacy related configuration for use in rrweb |
| 52 | + */ |
| 53 | +export function getPrivacyOptions({ |
| 54 | + mask, |
| 55 | + unmask, |
| 56 | + block, |
| 57 | + unblock, |
| 58 | + ignore, |
| 59 | + |
| 60 | + // eslint-disable-next-line deprecation/deprecation |
| 61 | + blockClass, |
| 62 | + // eslint-disable-next-line deprecation/deprecation |
| 63 | + blockSelector, |
| 64 | + // eslint-disable-next-line deprecation/deprecation |
| 65 | + maskTextClass, |
| 66 | + // eslint-disable-next-line deprecation/deprecation |
| 67 | + maskTextSelector, |
| 68 | + // eslint-disable-next-line deprecation/deprecation |
| 69 | + ignoreClass, |
| 70 | +}: GetPrivacyOptions): GetPrivacyReturn { |
| 71 | + const maskSelector = getOption(mask, ['.sentry-mask', '[data-sentry-mask]'], maskTextClass, maskTextSelector); |
| 72 | + const unmaskSelector = getOption(unmask, ['.sentry-unmask', '[data-sentry-unmask]']); |
| 73 | + |
| 74 | +const options: GetPrivacyReturn = { |
| 75 | + // We are making the decision to make text and input selectors the same |
| 76 | + maskTextSelector: maskSelector, |
| 77 | + unmaskTextSelector: unmaskSelector, |
| 78 | + maskInputSelector: maskSelector, |
| 79 | + unmaskInputSelector: unmaskSelector, |
| 80 | + |
| 81 | + blockSelector: getOption(block, ['.sentry-block', '[data-sentry-block]'], blockClass, blockSelector), |
| 82 | + unblockSelector: getOption(unblock, ['.sentry-unblock', '[data-sentry-unblock]']), |
| 83 | + ignoreSelector: getOption(ignore, ['.sentry-ignore', '[data-sentry-ignore]'], ignoreClass), |
| 84 | + }; |
| 85 | + |
| 86 | + |
| 87 | + if (blockClass instanceof RegExp) { |
| 88 | + options.blockClass = blockClass; |
| 89 | + } |
| 90 | + |
| 91 | + if (maskTextClass instanceof RegExp) { |
| 92 | + options.maskTextClass = maskTextClass; |
| 93 | + } |
| 94 | + |
| 95 | + return options |
| 96 | +} |
0 commit comments