From df16cd9c2cfc08bc999f436a11913df50e71ce19 Mon Sep 17 00:00:00 2001 From: Jan Monschke Date: Thu, 23 Nov 2023 16:39:23 +0100 Subject: [PATCH] [SecuritySolution] Remove `@kbn/subscription-tracking` (#171801) ## Summary The package data isn't needed anymore, so we can remove that package. On top, it seems like the package was causing some issues. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- .github/CODEOWNERS | 1 - package.json | 1 - packages/kbn-subscription-tracking/README.md | 35 ------ packages/kbn-subscription-tracking/index.ts | 17 --- .../kbn-subscription-tracking/jest.config.js | 13 --- .../kbn-subscription-tracking/kibana.jsonc | 5 - packages/kbn-subscription-tracking/mocks.tsx | 28 ----- .../kbn-subscription-tracking/package.json | 6 - .../src/helpers.test.ts | 45 -------- .../kbn-subscription-tracking/src/helpers.ts | 14 --- .../src/services.tsx | 70 ------------ .../src/subscription_elements.test.tsx | 108 ------------------ .../src/subscription_elements.tsx | 79 ------------- .../src/use_go_to_subscription.ts | 35 ------ .../src/use_impression.ts | 57 --------- .../kbn-subscription-tracking/tsconfig.json | 10 -- packages/kbn-subscription-tracking/types.ts | 47 -------- tsconfig.base.json | 8 +- .../components/subscription_not_allowed.tsx | 13 +-- .../public/test/test_provider.tsx | 9 +- .../cloud_security_posture/tsconfig.json | 1 - .../plugins/licensing/public/plugin.test.ts | 65 ----------- x-pack/plugins/licensing/public/plugin.ts | 2 - x-pack/plugins/licensing/tsconfig.json | 2 - .../security_solution/public/app/index.tsx | 9 +- .../security_solution/public/app/types.ts | 2 - .../insights/related_alerts_upsell.tsx | 19 ++- .../public/common/mock/test_providers.tsx | 95 ++++++++------- .../security_solution/public/plugin.tsx | 6 - .../plugins/security_solution/tsconfig.json | 3 +- .../public/components/paywall.tsx | 30 +++-- .../public/mocks/story_providers.tsx | 5 +- .../public/mocks/test_providers.tsx | 13 +-- .../threat_intelligence/public/plugin.tsx | 16 +-- .../plugins/threat_intelligence/tsconfig.json | 3 +- yarn.lock | 4 - 36 files changed, 95 insertions(+), 781 deletions(-) delete mode 100644 packages/kbn-subscription-tracking/README.md delete mode 100644 packages/kbn-subscription-tracking/index.ts delete mode 100644 packages/kbn-subscription-tracking/jest.config.js delete mode 100644 packages/kbn-subscription-tracking/kibana.jsonc delete mode 100644 packages/kbn-subscription-tracking/mocks.tsx delete mode 100644 packages/kbn-subscription-tracking/package.json delete mode 100644 packages/kbn-subscription-tracking/src/helpers.test.ts delete mode 100644 packages/kbn-subscription-tracking/src/helpers.ts delete mode 100644 packages/kbn-subscription-tracking/src/services.tsx delete mode 100644 packages/kbn-subscription-tracking/src/subscription_elements.test.tsx delete mode 100644 packages/kbn-subscription-tracking/src/subscription_elements.tsx delete mode 100644 packages/kbn-subscription-tracking/src/use_go_to_subscription.ts delete mode 100644 packages/kbn-subscription-tracking/src/use_impression.ts delete mode 100644 packages/kbn-subscription-tracking/tsconfig.json delete mode 100644 packages/kbn-subscription-tracking/types.ts diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 65a6381cb622c..2da7f440baf1e 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -753,7 +753,6 @@ test/server_integration/plugins/status_plugin_b @elastic/kibana-core packages/kbn-std @elastic/kibana-core packages/kbn-stdio-dev-helpers @elastic/kibana-operations packages/kbn-storybook @elastic/kibana-operations -packages/kbn-subscription-tracking @elastic/security-threat-hunting-investigations x-pack/plugins/synthetics @elastic/obs-ux-infra_services-team x-pack/test/alerting_api_integration/common/plugins/task_manager_fixture @elastic/response-ops x-pack/test/plugin_api_perf/plugins/task_manager_performance @elastic/response-ops diff --git a/package.json b/package.json index e49f3041a2138..2f334f54c42e2 100644 --- a/package.json +++ b/package.json @@ -750,7 +750,6 @@ "@kbn/status-plugin-a-plugin": "link:test/server_integration/plugins/status_plugin_a", "@kbn/status-plugin-b-plugin": "link:test/server_integration/plugins/status_plugin_b", "@kbn/std": "link:packages/kbn-std", - "@kbn/subscription-tracking": "link:packages/kbn-subscription-tracking", "@kbn/synthetics-plugin": "link:x-pack/plugins/synthetics", "@kbn/task-manager-fixture-plugin": "link:x-pack/test/alerting_api_integration/common/plugins/task_manager_fixture", "@kbn/task-manager-performance-plugin": "link:x-pack/test/plugin_api_perf/plugins/task_manager_performance", diff --git a/packages/kbn-subscription-tracking/README.md b/packages/kbn-subscription-tracking/README.md deleted file mode 100644 index 4f84593980881..0000000000000 --- a/packages/kbn-subscription-tracking/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# @kbn/subscription-tracking - -This package leverages the `@kbn/analytics-client` package to send dedicated subscription tracking events. - -It provides a set of React components that automatically track `impression` and `click` events. Consumers of those components need to specify a `subscription context` that gives more details on the type of feature that is advertised and the location of the upsell. - -```typescript -import { SubscriptionLink } from '@kbn/subscription-tracking'; -import type { SubscriptionContext } from '@kbn/subscription-tracking'; - -const subscriptionContext: SubscriptionContext = { - feature: 'threat-intelligence', - source: 'security__threat-intelligence', -}; - -export const Paywall = () => { - return ( -
- - Upgrade to Platinum to get this feature - -
- ); -}; -``` - -The example above uses a `SubscriptionLink` which is a wrapper of `EuiLink` . So it behaves just like a normal link. Alternatively, upsells can also use a `SubscriptionButton` or `SubscriptionButtonEmpty` which wrap `EuiButton` and `EuiButtonEmpty` respectively. - -When the link is mounted, it will send off an `impression` event with the given `subscriptionContext`. That piece of metadata consists of an identifier of the advertised feature (in this case `threat-intelligence`) and the `source` (aka location) of the impression (in this case the `threat-intelligence` page in the `security` solution). `source` follows the following format: `{solution-identifier}__location-identifier`. - -There are no special rules for how to name these identifiers but it's good practise to make sure that `feature` has the same value for all upsells advertising the same feature (e.g. use enums for features to prevent spelling mistakes). - -Upon interaction with the upsell link/button, a special `click` event is sent, which, again, contains the same subscription context. - -If you want to use the `subscription-tracking` elements in your app, you have to set up a `SubscriptionTrackingProvider` in your plugin setup and register the tracking events on startup. Have a look at https://github.com/elastic/kibana/pull/143910 for an example of an integration. diff --git a/packages/kbn-subscription-tracking/index.ts b/packages/kbn-subscription-tracking/index.ts deleted file mode 100644 index de17c595918d5..0000000000000 --- a/packages/kbn-subscription-tracking/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -export * from './src/subscription_elements'; - -export { - SubscriptionTrackingContext, - SubscriptionTrackingProvider, - registerEvents, -} from './src/services'; - -export * from './types'; diff --git a/packages/kbn-subscription-tracking/jest.config.js b/packages/kbn-subscription-tracking/jest.config.js deleted file mode 100644 index edc1839850dae..0000000000000 --- a/packages/kbn-subscription-tracking/jest.config.js +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -module.exports = { - preset: '@kbn/test', - rootDir: '../..', - roots: ['/packages/kbn-subscription-tracking'], -}; diff --git a/packages/kbn-subscription-tracking/kibana.jsonc b/packages/kbn-subscription-tracking/kibana.jsonc deleted file mode 100644 index e165baebfa76b..0000000000000 --- a/packages/kbn-subscription-tracking/kibana.jsonc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "type": "shared-common", - "id": "@kbn/subscription-tracking", - "owner": "@elastic/security-threat-hunting-investigations" -} diff --git a/packages/kbn-subscription-tracking/mocks.tsx b/packages/kbn-subscription-tracking/mocks.tsx deleted file mode 100644 index b918f9bba2828..0000000000000 --- a/packages/kbn-subscription-tracking/mocks.tsx +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import React, { FC } from 'react'; -import { analyticsClientMock } from '@kbn/analytics-client/src/mocks'; - -import { SubscriptionTrackingProvider } from './src/services'; - -const analyticsClientMockInst = analyticsClientMock.create(); - -/** - * Mock for the external services provider. Only use in tests! - */ -export const MockSubscriptionTrackingProvider: FC = ({ children }) => { - return ( - - {children} - - ); -}; diff --git a/packages/kbn-subscription-tracking/package.json b/packages/kbn-subscription-tracking/package.json deleted file mode 100644 index e9dd11b56c81b..0000000000000 --- a/packages/kbn-subscription-tracking/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "@kbn/subscription-tracking", - "private": true, - "version": "1.0.0", - "license": "SSPL-1.0 OR Elastic License 2.0" -} \ No newline at end of file diff --git a/packages/kbn-subscription-tracking/src/helpers.test.ts b/packages/kbn-subscription-tracking/src/helpers.test.ts deleted file mode 100644 index fa000567d35d3..0000000000000 --- a/packages/kbn-subscription-tracking/src/helpers.test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { isValidContext } from './helpers'; - -describe('tracking', () => { - describe('isValidLocation', () => { - it('identifies correct contexts', () => { - expect( - isValidContext({ - feature: 'test', - source: 'security__test', - }) - ).toBeTruthy(); - }); - - it('identifies incorrect contexts', () => { - expect( - isValidContext({ - feature: '', - source: 'security__', - }) - ).toBeFalsy(); - - expect( - isValidContext({ - feature: 'test', - source: 'security__', - }) - ).toBeFalsy(); - - expect( - isValidContext({ - feature: '', - source: 'security__test', - }) - ).toBeFalsy(); - }); - }); -}); diff --git a/packages/kbn-subscription-tracking/src/helpers.ts b/packages/kbn-subscription-tracking/src/helpers.ts deleted file mode 100644 index 251c0d1c04116..0000000000000 --- a/packages/kbn-subscription-tracking/src/helpers.ts +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import type { SubscriptionContextData } from '../types'; - -const sourceStringRegEx = /^(\w[\w\-_]*)__(\w[\w\-_]*)$/; -export function isValidContext(context: SubscriptionContextData): boolean { - return context.feature.length > 0 && sourceStringRegEx.test(context.source); -} diff --git a/packages/kbn-subscription-tracking/src/services.tsx b/packages/kbn-subscription-tracking/src/services.tsx deleted file mode 100644 index 857bd0b0dcd89..0000000000000 --- a/packages/kbn-subscription-tracking/src/services.tsx +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import React, { FC, useContext } from 'react'; -import type { AnalyticsClient, EventTypeOpts } from '@kbn/analytics-client'; -import { EVENT_NAMES, Services, SubscriptionContextData } from '../types'; - -export const SubscriptionTrackingContext = React.createContext(null); - -/** - * External services provider - */ -export const SubscriptionTrackingProvider: FC = ({ children, ...services }) => { - return ( - - {children} - - ); -}; - -/** - * React hook for accessing pre-wired services. - */ -export function useServices() { - const context = useContext(SubscriptionTrackingContext); - - if (!context) { - throw new Error( - 'SubscriptionTrackingContext is missing. Ensure your component or React root is wrapped with SubscriptionTrackingProvider.' - ); - } - - return context; -} - -const subscriptionContextSchema: EventTypeOpts['schema'] = { - source: { - type: 'keyword', - _meta: { - description: - 'A human-readable identifier describing the location of the beginning of the subscription flow', - }, - }, - feature: { - type: 'keyword', - _meta: { - description: 'A human-readable identifier describing the feature that is being promoted', - }, - }, -}; - -/** - * Registers the subscription-specific event types - */ -export function registerEvents(analyticsClient: Pick) { - analyticsClient.registerEventType({ - eventType: EVENT_NAMES.IMPRESSION, - schema: subscriptionContextSchema, - }); - - analyticsClient.registerEventType({ - eventType: EVENT_NAMES.CLICK, - schema: subscriptionContextSchema, - }); -} diff --git a/packages/kbn-subscription-tracking/src/subscription_elements.test.tsx b/packages/kbn-subscription-tracking/src/subscription_elements.test.tsx deleted file mode 100644 index 1795bbf42dd0c..0000000000000 --- a/packages/kbn-subscription-tracking/src/subscription_elements.test.tsx +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import React from 'react'; -import { render, screen } from '@testing-library/react'; -import { - SubscriptionLink, - SubscriptionButton, - SubscriptionButtonEmpty, -} from './subscription_elements'; -import { SubscriptionTrackingProvider } from './services'; -import { EVENT_NAMES, Services, SubscriptionContextData } from '../types'; -import { coolDownTimeMs, resetCoolDown } from './use_impression'; - -const testServices: Services = { - navigateToApp: jest.fn(), - analyticsClient: { - reportEvent: jest.fn(), - registerEventType: jest.fn(), - } as any, -}; -const testContext: SubscriptionContextData = { feature: 'test', source: 'security__test' }; - -const WithProviders: React.FC = ({ children }) => ( - - {children} - -); - -const renderWithProviders = (children: React.ReactElement) => - render(children, { wrapper: WithProviders }); - -const reset = () => { - jest.resetAllMocks(); - resetCoolDown(); -}; - -describe('SubscriptionElements', () => { - beforeAll(() => { - jest.useFakeTimers(); - }); - - afterAll(() => { - jest.useRealTimers(); - }); - - [SubscriptionButton, SubscriptionLink, SubscriptionButtonEmpty].forEach((SubscriptionElement) => { - describe(SubscriptionElement.name, () => { - beforeEach(reset); - - it('renders the children correctly', () => { - renderWithProviders( - Hello - ); - expect(screen.getByText('Hello')).toBeTruthy(); - }); - - it('fires an impression event when rendered', () => { - renderWithProviders(); - expect(testServices.analyticsClient.reportEvent).toHaveBeenCalledWith( - EVENT_NAMES.IMPRESSION, - testContext - ); - }); - - it('fires an impression event when rendered (but only once)', () => { - const { unmount } = renderWithProviders( - - ); - expect(testServices.analyticsClient.reportEvent).toHaveBeenCalledTimes(1); - unmount(); - - // does not create an impression again when remounted - const { unmount: unmountAgain } = renderWithProviders( - - ); - unmountAgain(); - expect(testServices.analyticsClient.reportEvent).toHaveBeenCalledTimes(1); - - // only creates anew impression when the cooldown time has passed - jest.setSystemTime(Date.now() + coolDownTimeMs); - renderWithProviders(); - expect(testServices.analyticsClient.reportEvent).toHaveBeenCalledTimes(2); - }); - - it('tracks a click when clicked and navigates to page', () => { - renderWithProviders( - hello - ); - - screen.getByText('hello').click(); - expect(testServices.analyticsClient.reportEvent).toHaveBeenCalledWith( - EVENT_NAMES.CLICK, - testContext - ); - expect(testServices.navigateToApp).toHaveBeenCalled(); - }); - }); - }); -}); diff --git a/packages/kbn-subscription-tracking/src/subscription_elements.tsx b/packages/kbn-subscription-tracking/src/subscription_elements.tsx deleted file mode 100644 index f29c58d8a0a41..0000000000000 --- a/packages/kbn-subscription-tracking/src/subscription_elements.tsx +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import React from 'react'; -import { EuiLink, EuiButton, EuiButtonEmpty } from '@elastic/eui'; -import type { EuiLinkProps, EuiButtonEmptyProps, EuiButtonProps } from '@elastic/eui'; -import { useGoToSubscription } from './use_go_to_subscription'; -import { useImpression } from './use_impression'; -import type { SubscriptionContextData } from '../types'; - -interface CommonProps { - /** The context information for this subscription element */ - subscriptionContext: SubscriptionContextData; -} - -export type SubscriptionLinkProps = EuiLinkProps & CommonProps; - -/** - * Wrapper around `EuiLink` that provides subscription events - */ -export function SubscriptionLink({ - subscriptionContext, - children, - ...restProps -}: SubscriptionLinkProps) { - const goToSubscription = useGoToSubscription({ subscriptionContext }); - useImpression(subscriptionContext); - - return ( - - {children} - - ); -} - -export type SubscriptionButtonProps = EuiButtonProps & CommonProps; - -/** - * Wrapper around `EuiButton` that provides subscription events - */ -export function SubscriptionButton({ - subscriptionContext, - children, - ...restProps -}: SubscriptionButtonProps) { - const goToSubscription = useGoToSubscription({ subscriptionContext }); - useImpression(subscriptionContext); - - return ( - - {children} - - ); -} - -export type SubscriptionButtonEmptyProps = EuiButtonEmptyProps & CommonProps; - -/** - * Wrapper around `EuiButtonEmpty` that provides subscription events - */ -export function SubscriptionButtonEmpty({ - subscriptionContext, - children, - ...restProps -}: SubscriptionButtonEmptyProps) { - const goToSubscription = useGoToSubscription({ subscriptionContext }); - useImpression(subscriptionContext); - - return ( - - {children} - - ); -} diff --git a/packages/kbn-subscription-tracking/src/use_go_to_subscription.ts b/packages/kbn-subscription-tracking/src/use_go_to_subscription.ts deleted file mode 100644 index 6c93fb27ee9bd..0000000000000 --- a/packages/kbn-subscription-tracking/src/use_go_to_subscription.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import { useCallback } from 'react'; -import { isValidContext } from './helpers'; -import { useServices } from './services'; -import { EVENT_NAMES, SubscriptionContextData } from '../types'; - -interface Options { - subscriptionContext: SubscriptionContextData; -} - -/** - * Provides a navigation function that navigates to the subscription - * management page. When the function executes, a click event with the - * given context is emitted. - */ -export const useGoToSubscription = ({ subscriptionContext }: Options) => { - const { navigateToApp, analyticsClient } = useServices(); - const goToSubscription = useCallback(() => { - if (isValidContext(subscriptionContext)) { - analyticsClient.reportEvent(EVENT_NAMES.CLICK, subscriptionContext); - } else { - // eslint-disable-next-line no-console - console.error('The provided subscription context is invalid', subscriptionContext); - } - navigateToApp('management', { path: 'stack/license_management' }); - }, [analyticsClient, navigateToApp, subscriptionContext]); - - return goToSubscription; -}; diff --git a/packages/kbn-subscription-tracking/src/use_impression.ts b/packages/kbn-subscription-tracking/src/use_impression.ts deleted file mode 100644 index eb8aa4c2e0ec5..0000000000000 --- a/packages/kbn-subscription-tracking/src/use_impression.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { useEffect } from 'react'; -import { isValidContext } from './helpers'; -import { useServices } from './services'; -import { EVENT_NAMES, SubscriptionContextData } from '../types'; - -/** - * Sends an impression event with the given context. - * - * Note: impression events are throttled and will not fire more - * often than once every 30 seconds. - */ -export const useImpression = (context: SubscriptionContextData) => { - const { analyticsClient } = useServices(); - - useEffect(() => { - if (!isValidContext(context)) { - // eslint-disable-next-line no-console - console.error('The provided subscription context is invalid', context); - return; - } - if (!isCoolingDown(context)) { - analyticsClient.reportEvent(EVENT_NAMES.IMPRESSION, context); - coolDown(context); - } - }, [analyticsClient, context]); -}; - -/** - * Impressions from the same context should not fire more than once every 30 seconds. - * This prevents logging too many impressions in case a page is reloaded often or - * if the user is navigating back and forth rapidly. - */ -export const coolDownTimeMs = 30 * 1000; -let impressionCooldown = new WeakMap(); - -function isCoolingDown(context: SubscriptionContextData) { - const previousLog = impressionCooldown.get(context); - - // we logged before and we are in the cooldown period - return previousLog && Date.now() - previousLog < coolDownTimeMs; -} - -function coolDown(context: SubscriptionContextData) { - impressionCooldown.set(context, Date.now()); -} - -export function resetCoolDown() { - impressionCooldown = new WeakMap(); -} diff --git a/packages/kbn-subscription-tracking/tsconfig.json b/packages/kbn-subscription-tracking/tsconfig.json deleted file mode 100644 index 677e9db998bb7..0000000000000 --- a/packages/kbn-subscription-tracking/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "compilerOptions": { - "outDir": "target/types", - "types": ["jest", "node", "react"] - }, - "include": ["**/*.ts", "**/*.tsx"], - "exclude": ["target/**/*"], - "kbn_references": ["@kbn/analytics-client"] -} diff --git a/packages/kbn-subscription-tracking/types.ts b/packages/kbn-subscription-tracking/types.ts deleted file mode 100644 index a2adf0c6d90c5..0000000000000 --- a/packages/kbn-subscription-tracking/types.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import type { AnalyticsClient } from '@kbn/analytics-client'; - -enum SolutionIdentifier { - observability = 'observability', - security = 'security', -} -type LocationString = string; -type SourceIdentifier = `${SolutionIdentifier}__${LocationString}`; -/** - * A piece of metadata which consists of an identifier of the advertised feature and - * the `source` (e.g. location) of the subscription element. - */ -export interface SubscriptionContextData { - /** - * A human-readable identifier describing the location of the beginning of the - * subscription flow. - * Location identifiers are prefixed with a solution identifier, e.g. `security__` - * - * @example "security__host-overview" - the user is looking at an upsell button - * on the host overview page in the security solution - */ - source: SourceIdentifier; - - /** - * A human-readable identifier describing the feature that is being promoted. - * - * @example "alerts-by-process-ancestry" - */ - feature: string; -} - -export interface Services { - navigateToApp: (app: string, options: { path: string }) => void; - analyticsClient: Pick; -} - -export enum EVENT_NAMES { - CLICK = 'subscription__upsell__click', - IMPRESSION = 'subscription__upsell__impression', -} diff --git a/tsconfig.base.json b/tsconfig.base.json index 860199a78c305..d21fd5f4359a1 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1500,8 +1500,6 @@ "@kbn/stdio-dev-helpers/*": ["packages/kbn-stdio-dev-helpers/*"], "@kbn/storybook": ["packages/kbn-storybook"], "@kbn/storybook/*": ["packages/kbn-storybook/*"], - "@kbn/subscription-tracking": ["packages/kbn-subscription-tracking"], - "@kbn/subscription-tracking/*": ["packages/kbn-subscription-tracking/*"], "@kbn/synthetics-plugin": ["x-pack/plugins/synthetics"], "@kbn/synthetics-plugin/*": ["x-pack/plugins/synthetics/*"], "@kbn/task-manager-fixture-plugin": ["x-pack/test/alerting_api_integration/common/plugins/task_manager_fixture"], @@ -1680,9 +1678,7 @@ "@kbn/zod-helpers/*": ["packages/kbn-zod-helpers/*"], // END AUTOMATED PACKAGE LISTING // Allows for importing from `kibana` package for the exported types. - "@emotion/core": [ - "typings/@emotion" - ], + "@emotion/core": ["typings/@emotion"] }, // Support .tsx files and transform JSX into calls to React.createElement "jsx": "react", @@ -1753,6 +1749,6 @@ "@kbn/ambient-ui-types", "@kbn/ambient-common-types", "@kbn/ambient-storybook-types" - ], + ] } } diff --git a/x-pack/plugins/cloud_security_posture/public/components/subscription_not_allowed.tsx b/x-pack/plugins/cloud_security_posture/public/components/subscription_not_allowed.tsx index 644455e5a2a68..a2d8f4fe32c0b 100644 --- a/x-pack/plugins/cloud_security_posture/public/components/subscription_not_allowed.tsx +++ b/x-pack/plugins/cloud_security_posture/public/components/subscription_not_allowed.tsx @@ -6,15 +6,8 @@ */ import React from 'react'; -import { EuiEmptyPrompt, EuiPageSection } from '@elastic/eui'; +import { EuiEmptyPrompt, EuiLink, EuiPageSection } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; -import { SubscriptionLink } from '@kbn/subscription-tracking'; -import type { SubscriptionContextData } from '@kbn/subscription-tracking'; - -const subscriptionContext: SubscriptionContextData = { - feature: 'cloud-security-posture', - source: 'security__cloud-security-posture', -}; export const SubscriptionNotAllowed = ({ licenseManagementLocator, @@ -41,12 +34,12 @@ export const SubscriptionNotAllowed = ({ defaultMessage="To use these cloud security features, you must {link}." values={{ link: ( - + - + ), }} /> diff --git a/x-pack/plugins/cloud_security_posture/public/test/test_provider.tsx b/x-pack/plugins/cloud_security_posture/public/test/test_provider.tsx index 3f89c934e5dd4..bdccb07851629 100755 --- a/x-pack/plugins/cloud_security_posture/public/test/test_provider.tsx +++ b/x-pack/plugins/cloud_security_posture/public/test/test_provider.tsx @@ -11,7 +11,6 @@ import { I18nProvider } from '@kbn/i18n-react'; // eslint-disable-next-line no-restricted-imports import { Router } from 'react-router-dom'; import { Route, Routes } from '@kbn/shared-ux-router'; -import { MockSubscriptionTrackingProvider } from '@kbn/subscription-tracking/mocks'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { coreMock } from '@kbn/core/public/mocks'; import { dataPluginMock } from '@kbn/data-plugin/public/mocks'; @@ -52,11 +51,9 @@ export const TestProvider: React.FC> = ({ - - - <>{children}} /> - - + + <>{children}} /> + diff --git a/x-pack/plugins/cloud_security_posture/tsconfig.json b/x-pack/plugins/cloud_security_posture/tsconfig.json index 113ddcb92202a..0d70ed5c6be6c 100755 --- a/x-pack/plugins/cloud_security_posture/tsconfig.json +++ b/x-pack/plugins/cloud_security_posture/tsconfig.json @@ -50,7 +50,6 @@ "@kbn/share-plugin", "@kbn/core-http-server", "@kbn/core-http-browser", - "@kbn/subscription-tracking", "@kbn/discover-utils", "@kbn/unified-data-table", "@kbn/cell-actions", diff --git a/x-pack/plugins/licensing/public/plugin.test.ts b/x-pack/plugins/licensing/public/plugin.test.ts index 9804f1ba8e1b7..5c571d0c6a40b 100644 --- a/x-pack/plugins/licensing/public/plugin.test.ts +++ b/x-pack/plugins/licensing/public/plugin.test.ts @@ -16,7 +16,6 @@ import { License } from '../common/license'; import { licenseMock } from '../common/licensing.mock'; import { coreMock } from '@kbn/core/public/mocks'; import { HttpInterceptor } from '@kbn/core/public'; -import type { AnalyticsServiceSetup } from '@kbn/core-analytics-browser'; const coreStart = coreMock.createStart(); describe('licensing plugin', () => { @@ -443,69 +442,5 @@ describe('licensing plugin', () => { expect(removeInterceptorMock).toHaveBeenCalledTimes(1); }); - - it('registers the subscription upsell events', async () => { - const sessionStorage = coreMock.createStorage(); - plugin = new LicensingPlugin(coreMock.createPluginInitializerContext(), sessionStorage); - - const coreSetup = coreMock.createSetup(); - - await plugin.setup(coreSetup); - await plugin.stop(); - - expect(findRegisteredEventTypeByName('subscription__upsell__click', coreSetup.analytics)) - .toMatchInlineSnapshot(` - Array [ - Object { - "eventType": "subscription__upsell__click", - "schema": Object { - "feature": Object { - "_meta": Object { - "description": "A human-readable identifier describing the feature that is being promoted", - }, - "type": "keyword", - }, - "source": Object { - "_meta": Object { - "description": "A human-readable identifier describing the location of the beginning of the subscription flow", - }, - "type": "keyword", - }, - }, - }, - ] - `); - expect(findRegisteredEventTypeByName('subscription__upsell__impression', coreSetup.analytics)) - .toMatchInlineSnapshot(` - Array [ - Object { - "eventType": "subscription__upsell__impression", - "schema": Object { - "feature": Object { - "_meta": Object { - "description": "A human-readable identifier describing the feature that is being promoted", - }, - "type": "keyword", - }, - "source": Object { - "_meta": Object { - "description": "A human-readable identifier describing the location of the beginning of the subscription flow", - }, - "type": "keyword", - }, - }, - }, - ] - `); - }); }); }); - -function findRegisteredEventTypeByName( - eventTypeName: string, - analyticsClientMock: jest.Mocked -) { - return analyticsClientMock.registerEventType.mock.calls.find( - ([{ eventType }]) => eventType === eventTypeName - )!; -} diff --git a/x-pack/plugins/licensing/public/plugin.ts b/x-pack/plugins/licensing/public/plugin.ts index bc350675d7dd2..3953a29a08214 100644 --- a/x-pack/plugins/licensing/public/plugin.ts +++ b/x-pack/plugins/licensing/public/plugin.ts @@ -8,7 +8,6 @@ import { Observable, Subject, Subscription } from 'rxjs'; import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from '@kbn/core/public'; -import { registerEvents as registerSubscriptionTrackingEvents } from '@kbn/subscription-tracking'; import { ILicense } from '../common/types'; import { LicensingPluginSetup, LicensingPluginStart } from './types'; import { createLicenseUpdate } from '../common/license_update'; @@ -85,7 +84,6 @@ export class LicensingPlugin implements Plugin { if (license.isAvailable) { diff --git a/x-pack/plugins/licensing/tsconfig.json b/x-pack/plugins/licensing/tsconfig.json index 1deb735f99466..804bf057afa6d 100644 --- a/x-pack/plugins/licensing/tsconfig.json +++ b/x-pack/plugins/licensing/tsconfig.json @@ -14,8 +14,6 @@ "@kbn/std", "@kbn/i18n", "@kbn/analytics-client", - "@kbn/subscription-tracking", - "@kbn/core-analytics-browser", "@kbn/logging-mocks" ], "exclude": ["target/**/*"] diff --git a/x-pack/plugins/security_solution/public/app/index.tsx b/x-pack/plugins/security_solution/public/app/index.tsx index 6f0fc3eb8d01c..3053590ae3d91 100644 --- a/x-pack/plugins/security_solution/public/app/index.tsx +++ b/x-pack/plugins/security_solution/public/app/index.tsx @@ -7,7 +7,6 @@ import React from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; -import { SubscriptionTrackingProvider } from '@kbn/subscription-tracking'; import { SecurityApp } from './app'; import type { RenderAppProps } from './types'; import { AppRoutes } from './app_routes'; @@ -21,7 +20,6 @@ export const renderApp = ({ usageCollection, subPluginRoutes, theme$, - subscriptionTrackingServices, }: RenderAppProps): (() => void) => { const ApplicationUsageTrackingProvider = usageCollection?.components.ApplicationUsageTrackingProvider ?? React.Fragment; @@ -34,12 +32,7 @@ export const renderApp = ({ theme$={theme$} > - - - + , element diff --git a/x-pack/plugins/security_solution/public/app/types.ts b/x-pack/plugins/security_solution/public/app/types.ts index 66bab19c945fe..578a4800f7f64 100644 --- a/x-pack/plugins/security_solution/public/app/types.ts +++ b/x-pack/plugins/security_solution/public/app/types.ts @@ -19,7 +19,6 @@ import type { RouteProps } from 'react-router-dom'; import type { AppMountParameters } from '@kbn/core/public'; import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public'; import type { TableState } from '@kbn/securitysolution-data-table'; -import type { Services as SubscriptionTrackingServices } from '@kbn/subscription-tracking'; import type { ExploreReducer, ExploreState } from '../explore'; import type { StartServices } from '../types'; @@ -30,7 +29,6 @@ export interface RenderAppProps extends AppMountParameters { services: StartServices; store: Store; subPluginRoutes: RouteProps[]; - subscriptionTrackingServices: SubscriptionTrackingServices; usageCollection?: UsageCollectionSetup; } diff --git a/x-pack/plugins/security_solution/public/common/components/event_details/insights/related_alerts_upsell.tsx b/x-pack/plugins/security_solution/public/common/components/event_details/insights/related_alerts_upsell.tsx index 303e55ff66b97..10a9c872e3911 100644 --- a/x-pack/plugins/security_solution/public/common/components/event_details/insights/related_alerts_upsell.tsx +++ b/x-pack/plugins/security_solution/public/common/components/event_details/insights/related_alerts_upsell.tsx @@ -6,17 +6,11 @@ */ import React from 'react'; -import { EuiFlexGroup, EuiFlexItem, EuiIcon, EuiText } from '@elastic/eui'; +import { EuiFlexGroup, EuiFlexItem, EuiIcon, EuiLink, EuiText } from '@elastic/eui'; import { euiStyled } from '@kbn/kibana-react-plugin/common'; -import { SubscriptionLink } from '@kbn/subscription-tracking'; -import type { SubscriptionContextData } from '@kbn/subscription-tracking'; import { INSIGHTS_UPSELL } from './translations'; - -const subscriptionContext: SubscriptionContextData = { - feature: 'alert-details-insights', - source: 'security__alert-details-flyout', -}; +import { useKibana } from '../../../lib/kibana'; const UpsellContainer = euiStyled.div` border: 1px solid ${({ theme }) => theme.eui.euiColorLightShade}; @@ -29,6 +23,7 @@ const StyledIcon = euiStyled(EuiIcon)` `; export const RelatedAlertsUpsell = React.memo(() => { + const { application } = useKibana().services; return ( @@ -37,13 +32,15 @@ export const RelatedAlertsUpsell = React.memo(() => { - {INSIGHTS_UPSELL} - + diff --git a/x-pack/plugins/security_solution/public/common/mock/test_providers.tsx b/x-pack/plugins/security_solution/public/common/mock/test_providers.tsx index a6779272da763..03dc789a41ad1 100644 --- a/x-pack/plugins/security_solution/public/common/mock/test_providers.tsx +++ b/x-pack/plugins/security_solution/public/common/mock/test_providers.tsx @@ -21,7 +21,6 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import type { Action } from '@kbn/ui-actions-plugin/public'; import { CellActionsProvider } from '@kbn/cell-actions'; import { ExpandableFlyoutProvider } from '@kbn/expandable-flyout'; -import { MockSubscriptionTrackingProvider } from '@kbn/subscription-tracking/mocks'; import { useKibana } from '../lib/kibana'; import { UpsellingProvider } from '../components/upselling_provider'; import { MockAssistantProvider } from './mock_assistant_provider'; @@ -76,29 +75,27 @@ export const TestProvidersComponent: React.FC = ({ return ( - - - - ({ eui: euiDarkVars, darkMode: true })}> - - - - - - Promise.resolve(cellActions)} - > - {children} - - - - - - - - - - + + + ({ eui: euiDarkVars, darkMode: true })}> + + + + + + Promise.resolve(cellActions)} + > + {children} + + + + + + + + + ); @@ -130,33 +127,31 @@ const TestProvidersWithPrivilegesComponent: React.FC = ({ return ( - - - ({ eui: euiDarkVars, darkMode: true })}> - - - - + ({ eui: euiDarkVars, darkMode: true })}> + + + + + Promise.resolve(cellActions)} > - Promise.resolve(cellActions)} - > - {children} - - - - - - - - + {children} + + + + + + + ); diff --git a/x-pack/plugins/security_solution/public/plugin.tsx b/x-pack/plugins/security_solution/public/plugin.tsx index c07273e59ed4a..e36dcd7991720 100644 --- a/x-pack/plugins/security_solution/public/plugin.tsx +++ b/x-pack/plugins/security_solution/public/plugin.tsx @@ -235,11 +235,6 @@ export class Plugin implements IPlugin { + const { + services: { application }, + } = useKibana(); return ( } @@ -52,12 +56,18 @@ export const Paywall: VFC = () => {
- + + application.navigateToApp('management', { + path: 'stack/license_management/home', + }) + } + > - +
diff --git a/x-pack/plugins/threat_intelligence/public/mocks/story_providers.tsx b/x-pack/plugins/threat_intelligence/public/mocks/story_providers.tsx index d13c3f561e748..249a9d05afbc9 100644 --- a/x-pack/plugins/threat_intelligence/public/mocks/story_providers.tsx +++ b/x-pack/plugins/threat_intelligence/public/mocks/story_providers.tsx @@ -12,7 +12,6 @@ import { CoreStart, IUiSettingsClient } from '@kbn/core/public'; import { TimelinesUIStart } from '@kbn/timelines-plugin/public'; import { EuiThemeProvider } from '@kbn/kibana-react-plugin/common'; import { RequestAdapter } from '@kbn/inspector-plugin/common'; -import { MockSubscriptionTrackingProvider } from '@kbn/subscription-tracking/mocks'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import type { SettingsStart } from '@kbn/core-ui-settings-browser'; import { mockIndicatorsFiltersContext } from './mock_indicators_filters_context'; @@ -108,9 +107,7 @@ export const StoryProvidersComponent: VFC = ({ - - {children} - + {children} diff --git a/x-pack/plugins/threat_intelligence/public/mocks/test_providers.tsx b/x-pack/plugins/threat_intelligence/public/mocks/test_providers.tsx index 12c42052ee26f..37360284b6aa7 100644 --- a/x-pack/plugins/threat_intelligence/public/mocks/test_providers.tsx +++ b/x-pack/plugins/threat_intelligence/public/mocks/test_providers.tsx @@ -17,7 +17,6 @@ import { unifiedSearchPluginMock } from '@kbn/unified-search-plugin/public/mocks import { createTGridMocks } from '@kbn/timelines-plugin/public/mock'; import { EuiThemeProvider } from '@kbn/kibana-react-plugin/common'; import { RequestAdapter } from '@kbn/inspector-plugin/common'; -import { MockSubscriptionTrackingProvider } from '@kbn/subscription-tracking/mocks'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { MemoryRouter } from 'react-router-dom'; import { casesPluginMock } from '@kbn/cases-plugin/public/mocks'; @@ -142,13 +141,11 @@ export const TestProvidersComponent: FC = ({ children }) => ( - - - - {children} - - - + + + {children} + + diff --git a/x-pack/plugins/threat_intelligence/public/plugin.tsx b/x-pack/plugins/threat_intelligence/public/plugin.tsx index e30e9f92c0a5b..49f6b3b7724bf 100755 --- a/x-pack/plugins/threat_intelligence/public/plugin.tsx +++ b/x-pack/plugins/threat_intelligence/public/plugin.tsx @@ -11,7 +11,6 @@ import { Provider as ReduxStoreProvider } from 'react-redux'; import React, { Suspense } from 'react'; import { __IntlProvider as IntlProvider } from '@kbn/i18n-react'; import { ExternalReferenceAttachmentType } from '@kbn/cases-plugin/public/client/attachment_framework/types'; -import { SubscriptionTrackingProvider } from '@kbn/subscription-tracking'; import { generateAttachmentType } from './modules/cases/utils/attachments'; import { KibanaContextProvider } from './hooks/use_kibana'; import { @@ -44,16 +43,11 @@ export const createApp = - - - }> - - - - + + }> + + + diff --git a/x-pack/plugins/threat_intelligence/tsconfig.json b/x-pack/plugins/threat_intelligence/tsconfig.json index 661186c943b54..2e390483ab22c 100644 --- a/x-pack/plugins/threat_intelligence/tsconfig.json +++ b/x-pack/plugins/threat_intelligence/tsconfig.json @@ -32,8 +32,7 @@ "@kbn/utility-types", "@kbn/ui-theme", "@kbn/securitysolution-io-ts-list-types", - "@kbn/core-ui-settings-browser", - "@kbn/subscription-tracking" + "@kbn/core-ui-settings-browser" ], "exclude": ["target/**/*"] } diff --git a/yarn.lock b/yarn.lock index f481f66307937..584c660603157 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5937,10 +5937,6 @@ version "0.0.0" uid "" -"@kbn/subscription-tracking@link:packages/kbn-subscription-tracking": - version "0.0.0" - uid "" - "@kbn/synthetics-plugin@link:x-pack/plugins/synthetics": version "0.0.0" uid ""