Create packages for browser-side analytics service (#134307)

* Create client-side analytics service packages

* move all the things

* start to adapt imports

* fix more imports

* update generated doc

* updating READMEs
This commit is contained in:
Pierre Gayvallet 2022-06-16 12:17:29 +02:00 committed by GitHub
parent b041f04893
commit 9a15b67eb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
55 changed files with 764 additions and 119 deletions

View file

@ -1,13 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [AnalyticsServiceSetup](./kibana-plugin-core-public.analyticsservicesetup.md)
## AnalyticsServiceSetup type
Exposes the public APIs of the AnalyticsClient during the setup phase.
<b>Signature:</b>
```typescript
export declare type AnalyticsServiceSetup = Omit<AnalyticsClient, 'shutdown'>;
```

View file

@ -1,13 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [AnalyticsServiceStart](./kibana-plugin-core-public.analyticsservicestart.md)
## AnalyticsServiceStart type
Exposes the public APIs of the AnalyticsClient during the start phase
<b>Signature:</b>
```typescript
export declare type AnalyticsServiceStart = Pick<AnalyticsClient, 'optIn' | 'reportEvent' | 'telemetryCounter$'>;
```

View file

@ -4,7 +4,6 @@
## CoreSetup.analytics property
[AnalyticsServiceSetup](./kibana-plugin-core-public.analyticsservicesetup.md)
<b>Signature:</b>

View file

@ -16,7 +16,7 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
| Property | Type | Description |
| --- | --- | --- |
| [analytics](./kibana-plugin-core-public.coresetup.analytics.md) | AnalyticsServiceSetup | [AnalyticsServiceSetup](./kibana-plugin-core-public.analyticsservicesetup.md) |
| [analytics](./kibana-plugin-core-public.coresetup.analytics.md) | AnalyticsServiceSetup | |
| [application](./kibana-plugin-core-public.coresetup.application.md) | ApplicationSetup | [ApplicationSetup](./kibana-plugin-core-public.applicationsetup.md) |
| [executionContext](./kibana-plugin-core-public.coresetup.executioncontext.md) | ExecutionContextSetup | [ExecutionContextSetup](./kibana-plugin-core-public.executioncontextsetup.md) |
| [fatalErrors](./kibana-plugin-core-public.coresetup.fatalerrors.md) | FatalErrorsSetup | [FatalErrorsSetup](./kibana-plugin-core-public.fatalerrorssetup.md) |

View file

@ -4,7 +4,6 @@
## CoreStart.analytics property
[AnalyticsServiceStart](./kibana-plugin-core-public.analyticsservicestart.md)
<b>Signature:</b>

View file

@ -16,7 +16,7 @@ export interface CoreStart
| Property | Type | Description |
| --- | --- | --- |
| [analytics](./kibana-plugin-core-public.corestart.analytics.md) | AnalyticsServiceStart | [AnalyticsServiceStart](./kibana-plugin-core-public.analyticsservicestart.md) |
| [analytics](./kibana-plugin-core-public.corestart.analytics.md) | AnalyticsServiceStart | |
| [application](./kibana-plugin-core-public.corestart.application.md) | ApplicationStart | [ApplicationStart](./kibana-plugin-core-public.applicationstart.md) |
| [chrome](./kibana-plugin-core-public.corestart.chrome.md) | ChromeStart | [ChromeStart](./kibana-plugin-core-public.chromestart.md) |
| [deprecations](./kibana-plugin-core-public.corestart.deprecations.md) | DeprecationsServiceStart | [DeprecationsServiceStart](./kibana-plugin-core-public.deprecationsservicestart.md) |

View file

@ -148,8 +148,6 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| Type Alias | Description |
| --- | --- |
| [AnalyticsServiceSetup](./kibana-plugin-core-public.analyticsservicesetup.md) | Exposes the public APIs of the AnalyticsClient during the setup phase. |
| [AnalyticsServiceStart](./kibana-plugin-core-public.analyticsservicestart.md) | Exposes the public APIs of the AnalyticsClient during the start phase |
| [AppDeepLink](./kibana-plugin-core-public.appdeeplink.md) | Input type for registering secondary in-app locations for an application.<!-- -->Deep links must include at least one of <code>path</code> or <code>deepLinks</code>. A deep link that does not have a <code>path</code> represents a topological level in the application's hierarchy, but does not have a destination URL that is user-accessible. |
| [AppLeaveAction](./kibana-plugin-core-public.appleaveaction.md) | Possible actions to return from a [AppLeaveHandler](./kibana-plugin-core-public.appleavehandler.md)<!-- -->See [AppLeaveConfirmAction](./kibana-plugin-core-public.appleaveconfirmaction.md) and [AppLeaveDefaultAction](./kibana-plugin-core-public.appleavedefaultaction.md) |
| [AppLeaveHandler](./kibana-plugin-core-public.appleavehandler.md) | A handler that will be executed before leaving the application, either when going to another application or when closing the browser tab or manually changing the url. Should return <code>confirm</code> to prompt a message to the user before leaving the page, or <code>default</code> to keep the default behavior (doing nothing).<!-- -->See [AppMountParameters](./kibana-plugin-core-public.appmountparameters.md) for detailed usage examples. |

View file

@ -147,7 +147,11 @@
"@kbn/config": "link:bazel-bin/packages/kbn-config",
"@kbn/config-mocks": "link:bazel-bin/packages/kbn-config-mocks",
"@kbn/config-schema": "link:bazel-bin/packages/kbn-config-schema",
"@kbn/core-analytics-browser": "link:bazel-bin/packages/core/analytics/core-analytics-browser",
"@kbn/core-analytics-browser-internal": "link:bazel-bin/packages/core/analytics/core-analytics-browser-internal",
"@kbn/core-analytics-browser-mocks": "link:bazel-bin/packages/core/analytics/core-analytics-browser-mocks",
"@kbn/core-base-browser-internal": "link:bazel-bin/packages/core/base/core-base-browser-internal",
"@kbn/core-base-browser-mocks": "link:bazel-bin/packages/core/base/core-base-browser-mocks",
"@kbn/core-base-common": "link:bazel-bin/packages/core/base/core-base-common",
"@kbn/core-base-common-internal": "link:bazel-bin/packages/core/base/core-base-common-internal",
"@kbn/core-base-server-internal": "link:bazel-bin/packages/core/base/core-base-server-internal",
@ -659,8 +663,12 @@
"@types/kbn__config": "link:bazel-bin/packages/kbn-config/npm_module_types",
"@types/kbn__config-mocks": "link:bazel-bin/packages/kbn-config-mocks/npm_module_types",
"@types/kbn__config-schema": "link:bazel-bin/packages/kbn-config-schema/npm_module_types",
"@types/kbn__core-analytics-browser": "link:bazel-bin/packages/core/analytics/core-analytics-browser/npm_module_types",
"@types/kbn__core-analytics-browser-internal": "link:bazel-bin/packages/core/analytics/core-analytics-browser-internal/npm_module_types",
"@types/kbn__core-analytics-browser-mocks": "link:bazel-bin/packages/core/analytics/core-analytics-browser-mocks/npm_module_types",
"@types/kbn__core-base-browser": "link:bazel-bin/packages/core/base/core-base-browser/npm_module_types",
"@types/kbn__core-base-browser-internal": "link:bazel-bin/packages/core/base/core-base-browser-internal/npm_module_types",
"@types/kbn__core-base-browser-mocks": "link:bazel-bin/packages/core/base/core-base-browser-mocks/npm_module_types",
"@types/kbn__core-base-common": "link:bazel-bin/packages/core/base/core-base-common/npm_module_types",
"@types/kbn__core-base-common-internal": "link:bazel-bin/packages/core/base/core-base-common-internal/npm_module_types",
"@types/kbn__core-base-server": "link:bazel-bin/packages/core/base/core-base-server/npm_module_types",

View file

@ -14,7 +14,11 @@ filegroup(
"//packages/analytics/shippers/elastic_v3/common:build",
"//packages/analytics/shippers/elastic_v3/server:build",
"//packages/analytics/shippers/fullstory:build",
"//packages/core/analytics/core-analytics-browser-internal:build",
"//packages/core/analytics/core-analytics-browser-mocks:build",
"//packages/core/analytics/core-analytics-browser:build",
"//packages/core/base/core-base-browser-internal:build",
"//packages/core/base/core-base-browser-mocks:build",
"//packages/core/base/core-base-common-internal:build",
"//packages/core/base/core-base-common:build",
"//packages/core/base/core-base-server-internal:build",
@ -154,7 +158,11 @@ filegroup(
"//packages/analytics/shippers/elastic_v3/common:build_types",
"//packages/analytics/shippers/elastic_v3/server:build_types",
"//packages/analytics/shippers/fullstory:build_types",
"//packages/core/analytics/core-analytics-browser-internal:build_types",
"//packages/core/analytics/core-analytics-browser-mocks:build_types",
"//packages/core/analytics/core-analytics-browser:build_types",
"//packages/core/base/core-base-browser-internal:build_types",
"//packages/core/base/core-base-browser-mocks:build_types",
"//packages/core/base/core-base-common-internal:build_types",
"//packages/core/base/core-base-common:build_types",
"//packages/core/base/core-base-server-internal:build_types",

View file

@ -0,0 +1,117 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
PKG_DIRNAME = "core-analytics-browser-internal"
PKG_REQUIRE_NAME = "@kbn/core-analytics-browser-internal"
SOURCE_FILES = glob(
[
"src/**/*.ts",
"src/**/*.tsx",
],
exclude = [
"**/*.test.*",
],
)
SRCS = SOURCE_FILES
filegroup(
name = "srcs",
srcs = SRCS,
)
NPM_MODULE_EXTRA_FILES = [
"package.json",
]
RUNTIME_DEPS = [
"@npm//rxjs",
"@npm//uuid",
"//packages/analytics/client",
"//packages/core/base/core-base-browser-mocks",
"//packages/core/injected-metadata/core-injected-metadata-browser-mocks",
]
TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
"@npm//@types/uuid",
"@npm//rxjs",
"//packages/kbn-logging:npm_module_types",
"//packages/analytics/client:npm_module_types",
"//packages/core/base/core-base-browser-internal:npm_module_types",
"//packages/core/injected-metadata/core-injected-metadata-browser-internal:npm_module_types",
"//packages/core/analytics/core-analytics-browser:npm_module_types",
"//packages/core/base/core-base-browser-mocks:npm_module_types",
"//packages/core/injected-metadata/core-injected-metadata-browser-mocks:npm_module_types",
]
jsts_transpiler(
name = "target_node",
srcs = SRCS,
build_pkg_name = package_name(),
)
jsts_transpiler(
name = "target_web",
srcs = SRCS,
build_pkg_name = package_name(),
web = True,
)
ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig.base.json",
"//:tsconfig.bazel.json",
],
)
ts_project(
name = "tsc_types",
args = ['--pretty'],
srcs = SRCS,
deps = TYPES_DEPS,
declaration = True,
emit_declaration_only = True,
out_dir = "target_types",
root_dir = "src",
tsconfig = ":tsconfig",
)
js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
pkg_npm(
name = "npm_module",
deps = [":" + PKG_DIRNAME],
)
filegroup(
name = "build",
srcs = [":npm_module"],
visibility = ["//visibility:public"],
)
pkg_npm_types(
name = "npm_module_types",
srcs = SRCS,
deps = [":tsc_types"],
package_name = PKG_REQUIRE_NAME,
tsconfig = ":tsconfig",
visibility = ["//visibility:public"],
)
filegroup(
name = "build_types",
srcs = [":npm_module_types"],
visibility = ["//visibility:public"],
)

View file

@ -0,0 +1,3 @@
# @kbn/core-analytics-browser-internal
This package contains the internal types and implementation for Core's browser-side analytics service.

View file

@ -0,0 +1,13 @@
/*
* 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: ['<rootDir>/packages/core/analytics/core-analytics-browser-internal'],
};

View file

@ -0,0 +1,8 @@
{
"name": "@kbn/core-analytics-browser-internal",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
"browser": "./target_web/index.js",
"license": "SSPL-1.0 OR Elastic License 2.0"
}

View file

@ -7,15 +7,16 @@
*/
import { firstValueFrom, Observable } from 'rxjs';
import { coreContextMock } from '@kbn/core-base-browser-mocks';
import { injectedMetadataServiceMock } from '@kbn/core-injected-metadata-browser-mocks';
import { analyticsClientMock } from './analytics_service.test.mocks';
import { coreMock, injectedMetadataServiceMock } from '../mocks';
import { AnalyticsService } from './analytics_service';
describe('AnalyticsService', () => {
let analyticsService: AnalyticsService;
beforeEach(() => {
jest.clearAllMocks();
analyticsService = new AnalyticsService(coreMock.createCoreContext());
analyticsService = new AnalyticsService(coreContextMock.create());
});
test('should register some context providers on creation', async () => {
expect(analyticsClientMock.registerContextProvider).toHaveBeenCalledTimes(3);

View file

@ -11,26 +11,11 @@ import type { AnalyticsClient } from '@kbn/analytics-client';
import { createAnalytics } from '@kbn/analytics-client';
import type { CoreContext } from '@kbn/core-base-browser-internal';
import type { InternalInjectedMetadataSetup } from '@kbn/core-injected-metadata-browser-internal';
import type { AnalyticsServiceSetup, AnalyticsServiceStart } from '@kbn/core-analytics-browser';
import { trackClicks } from './track_clicks';
import { getSessionId } from './get_session_id';
import { createLogger } from './logger';
/**
* Exposes the public APIs of the AnalyticsClient during the setup phase.
* {@link AnalyticsClient}
* @public
*/
export type AnalyticsServiceSetup = Omit<AnalyticsClient, 'shutdown'>;
/**
* Exposes the public APIs of the AnalyticsClient during the start phase
* {@link AnalyticsClient}
* @public
*/
export type AnalyticsServiceStart = Pick<
AnalyticsClient,
'optIn' | 'reportEvent' | 'telemetryCounter$'
>;
/** @internal */
export interface AnalyticsServiceSetupDeps {
injectedMetadata: InternalInjectedMetadataSetup;

View file

@ -0,0 +1,10 @@
/*
* 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 type { AnalyticsServiceSetupDeps } from './analytics_service';
export { AnalyticsService } from './analytics_service';

View file

@ -0,0 +1,17 @@
{
"extends": "../../../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"rootDir": "src",
"stripInternal": false,
"types": [
"jest",
"node"
]
},
"include": [
"src/**/*"
]
}

View file

@ -0,0 +1,106 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
PKG_DIRNAME = "core-analytics-browser-mocks"
PKG_REQUIRE_NAME = "@kbn/core-analytics-browser-mocks"
SOURCE_FILES = glob(
[
"src/**/*.ts",
"src/**/*.tsx",
],
exclude = [
"**/*.test.*",
],
)
SRCS = SOURCE_FILES
filegroup(
name = "srcs",
srcs = SRCS,
)
NPM_MODULE_EXTRA_FILES = [
"package.json",
]
RUNTIME_DEPS = [
]
TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
"//packages/kbn-utility-types:npm_module_types",
"//packages/core/analytics/core-analytics-browser:npm_module_types",
"//packages/core/analytics/core-analytics-browser-internal:npm_module_types",
]
jsts_transpiler(
name = "target_node",
srcs = SRCS,
build_pkg_name = package_name(),
)
jsts_transpiler(
name = "target_web",
srcs = SRCS,
build_pkg_name = package_name(),
web = True,
)
ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig.base.json",
"//:tsconfig.bazel.json",
],
)
ts_project(
name = "tsc_types",
args = ['--pretty'],
srcs = SRCS,
deps = TYPES_DEPS,
declaration = True,
emit_declaration_only = True,
out_dir = "target_types",
root_dir = "src",
tsconfig = ":tsconfig",
)
js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
pkg_npm(
name = "npm_module",
deps = [":" + PKG_DIRNAME],
)
filegroup(
name = "build",
srcs = [":npm_module"],
visibility = ["//visibility:public"],
)
pkg_npm_types(
name = "npm_module_types",
srcs = SRCS,
deps = [":tsc_types"],
package_name = PKG_REQUIRE_NAME,
tsconfig = ":tsconfig",
visibility = ["//visibility:public"],
)
filegroup(
name = "build_types",
srcs = [":npm_module_types"],
visibility = ["//visibility:public"],
)

View file

@ -0,0 +1,3 @@
# @kbn/core-analytics-browser-mocks
This package contains the mocks for Core's browser-side analytics service.

View file

@ -0,0 +1,13 @@
/*
* 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: ['<rootDir>/packages/core/analytics/core-analytics-browser-mocks'],
};

View file

@ -0,0 +1,8 @@
{
"name": "@kbn/core-analytics-browser-mocks",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
"browser": "./target_web/index.js",
"license": "SSPL-1.0 OR Elastic License 2.0"
}

View file

@ -8,11 +8,8 @@
import { Subject } from 'rxjs';
import type { PublicMethodsOf } from '@kbn/utility-types';
import type {
AnalyticsService,
AnalyticsServiceSetup,
AnalyticsServiceStart,
} from './analytics_service';
import type { AnalyticsServiceSetup, AnalyticsServiceStart } from '@kbn/core-analytics-browser';
import type { AnalyticsService } from '@kbn/core-analytics-browser-internal';
type AnalyticsServiceContract = PublicMethodsOf<AnalyticsService>;

View file

@ -0,0 +1,9 @@
/*
* 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 { analyticsServiceMock } from './analytics_service.mock';

View file

@ -0,0 +1,17 @@
{
"extends": "../../../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"rootDir": "src",
"stripInternal": false,
"types": [
"jest",
"node"
]
},
"include": [
"src/**/*"
]
}

View file

@ -0,0 +1,104 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
PKG_DIRNAME = "core-analytics-browser"
PKG_REQUIRE_NAME = "@kbn/core-analytics-browser"
SOURCE_FILES = glob(
[
"src/**/*.ts",
"src/**/*.tsx",
],
exclude = [
"**/*.test.*",
],
)
SRCS = SOURCE_FILES
filegroup(
name = "srcs",
srcs = SRCS,
)
NPM_MODULE_EXTRA_FILES = [
"package.json",
]
RUNTIME_DEPS = [
]
TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
"//packages/analytics/client:npm_module_types",
]
jsts_transpiler(
name = "target_node",
srcs = SRCS,
build_pkg_name = package_name(),
)
jsts_transpiler(
name = "target_web",
srcs = SRCS,
build_pkg_name = package_name(),
web = True,
)
ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig.base.json",
"//:tsconfig.bazel.json",
],
)
ts_project(
name = "tsc_types",
args = ['--pretty'],
srcs = SRCS,
deps = TYPES_DEPS,
declaration = True,
emit_declaration_only = True,
out_dir = "target_types",
root_dir = "src",
tsconfig = ":tsconfig",
)
js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
pkg_npm(
name = "npm_module",
deps = [":" + PKG_DIRNAME],
)
filegroup(
name = "build",
srcs = [":npm_module"],
visibility = ["//visibility:public"],
)
pkg_npm_types(
name = "npm_module_types",
srcs = SRCS,
deps = [":tsc_types"],
package_name = PKG_REQUIRE_NAME,
tsconfig = ":tsconfig",
visibility = ["//visibility:public"],
)
filegroup(
name = "build_types",
srcs = [":npm_module_types"],
visibility = ["//visibility:public"],
)

View file

@ -0,0 +1,3 @@
# @kbn/core-analytics-browser
This package contains the public types for Core's browser-side analytics service.

View file

@ -0,0 +1,13 @@
/*
* 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: ['<rootDir>/packages/core/analytics/core-analytics-browser'],
};

View file

@ -0,0 +1,8 @@
{
"name": "@kbn/core-analytics-browser",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
"browser": "./target_web/index.js",
"license": "SSPL-1.0 OR Elastic License 2.0"
}

View file

@ -6,20 +6,4 @@
* Side Public License, v 1.
*/
export { AnalyticsService } from './analytics_service';
export type { AnalyticsServiceSetup, AnalyticsServiceStart } from './analytics_service';
export type {
AnalyticsClient,
Event,
EventContext,
EventType,
EventTypeOpts,
IShipper,
ShipperClassConstructor,
OptInConfig,
ContextProviderOpts,
TelemetryCounter,
} from '@kbn/analytics-client';
export { TelemetryCounterType } from '@kbn/analytics-client';
export type { AnalyticsServiceSetup, AnalyticsServiceStart } from './types';

View file

@ -0,0 +1,26 @@
/*
* 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';
/**
* Exposes the public APIs of the AnalyticsClient during the setup phase.
* {@link AnalyticsClient}
* @public
*/
export type AnalyticsServiceSetup = Omit<AnalyticsClient, 'shutdown'>;
/**
* Exposes the public APIs of the AnalyticsClient during the start phase
* {@link AnalyticsClient}
* @public
*/
export type AnalyticsServiceStart = Pick<
AnalyticsClient,
'optIn' | 'reportEvent' | 'telemetryCounter$'
>;

View file

@ -0,0 +1,17 @@
{
"extends": "../../../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"rootDir": "src",
"stripInternal": false,
"types": [
"jest",
"node"
]
},
"include": [
"src/**/*"
]
}

View file

@ -0,0 +1,104 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
PKG_DIRNAME = "core-base-browser-mocks"
PKG_REQUIRE_NAME = "@kbn/core-base-browser-mocks"
SOURCE_FILES = glob(
[
"src/**/*.ts",
"src/**/*.tsx",
],
exclude = [
"**/*.test.*",
],
)
SRCS = SOURCE_FILES
filegroup(
name = "srcs",
srcs = SRCS,
)
NPM_MODULE_EXTRA_FILES = [
"package.json",
]
RUNTIME_DEPS = [
]
TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
"//packages/core/base/core-base-browser-internal:npm_module_types",
]
jsts_transpiler(
name = "target_node",
srcs = SRCS,
build_pkg_name = package_name(),
)
jsts_transpiler(
name = "target_web",
srcs = SRCS,
build_pkg_name = package_name(),
web = True,
)
ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig.base.json",
"//:tsconfig.bazel.json",
],
)
ts_project(
name = "tsc_types",
args = ['--pretty'],
srcs = SRCS,
deps = TYPES_DEPS,
declaration = True,
emit_declaration_only = True,
out_dir = "target_types",
root_dir = "src",
tsconfig = ":tsconfig",
)
js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
pkg_npm(
name = "npm_module",
deps = [":" + PKG_DIRNAME],
)
filegroup(
name = "build",
srcs = [":npm_module"],
visibility = ["//visibility:public"],
)
pkg_npm_types(
name = "npm_module_types",
srcs = SRCS,
deps = [":tsc_types"],
package_name = PKG_REQUIRE_NAME,
tsconfig = ":tsconfig",
visibility = ["//visibility:public"],
)
filegroup(
name = "build_types",
srcs = [":npm_module_types"],
visibility = ["//visibility:public"],
)

View file

@ -0,0 +1,3 @@
# @kbn/core-base-browser-mocks
This package contains the base Core browser mocks.

View file

@ -0,0 +1,13 @@
/*
* 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: ['<rootDir>/packages/core/base/core-base-browser-mocks'],
};

View file

@ -0,0 +1,8 @@
{
"name": "@kbn/core-base-browser-mocks",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
"browser": "./target_web/index.js",
"license": "SSPL-1.0 OR Elastic License 2.0"
}

View file

@ -0,0 +1,33 @@
/*
* 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 { CoreContext } from '@kbn/core-base-browser-internal';
function createCoreContext({ production = false }: { production?: boolean } = {}): CoreContext {
return {
coreId: Symbol('core context mock'),
env: {
mode: {
dev: !production,
name: production ? 'production' : 'development',
prod: production,
},
packageInfo: {
version: 'version',
branch: 'branch',
buildNum: 100,
buildSha: 'buildSha',
dist: false,
},
},
};
}
export const coreContextMock = {
create: createCoreContext,
};

View file

@ -0,0 +1,9 @@
/*
* 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 { coreContextMock } from './core_context.mock';

View file

@ -0,0 +1,17 @@
{
"extends": "../../../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"rootDir": "src",
"stripInternal": false,
"types": [
"jest",
"node"
]
},
"include": [
"src/**/*"
]
}

View file

@ -1,3 +1,3 @@
# @kbn/core-base-server-mocks
Empty package generated by @kbn/generate
This package contains the base Core server mocks.

View file

@ -9,6 +9,7 @@
import { injectedMetadataServiceMock } from '@kbn/core-injected-metadata-browser-mocks';
import { docLinksServiceMock } from '@kbn/core-doc-links-browser-mocks';
import { themeServiceMock } from '@kbn/core-theme-browser-mocks';
import { analyticsServiceMock } from '@kbn/core-analytics-browser-mocks';
import { applicationServiceMock } from './application/application_service.mock';
import { chromeServiceMock } from './chrome/chrome_service.mock';
import { fatalErrorsServiceMock } from './fatal_errors/fatal_errors_service.mock';
@ -21,13 +22,12 @@ import { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock';
import { renderingServiceMock } from './rendering/rendering_service.mock';
import { integrationsServiceMock } from './integrations/integrations_service.mock';
import { coreAppMock } from './core_app/core_app.mock';
import { analyticsServiceMock } from './analytics/analytics_service.mock';
export const analyticsServiceStartMock = analyticsServiceMock.createAnalyticsServiceStart();
export const MockAnalyticsService = analyticsServiceMock.create();
MockAnalyticsService.start.mockReturnValue(analyticsServiceStartMock);
export const AnalyticsServiceConstructor = jest.fn().mockReturnValue(MockAnalyticsService);
jest.doMock('./analytics', () => ({
jest.doMock('@kbn/core-analytics-browser-internal', () => ({
AnalyticsService: AnalyticsServiceConstructor,
}));

View file

@ -15,6 +15,8 @@ import {
} from '@kbn/core-injected-metadata-browser-internal';
import { DocLinksService } from '@kbn/core-doc-links-browser-internal';
import { ThemeService } from '@kbn/core-theme-browser-internal';
import type { AnalyticsServiceSetup } from '@kbn/core-analytics-browser';
import { AnalyticsService } from '@kbn/core-analytics-browser-internal';
import { CoreSetup, CoreStart } from '.';
import { ChromeService } from './chrome';
import { FatalErrorsService, FatalErrorsSetup } from './fatal_errors';
@ -32,8 +34,6 @@ import { DeprecationsService } from './deprecations';
import { CoreApp } from './core_app';
import type { InternalApplicationSetup, InternalApplicationStart } from './application/types';
import { ExecutionContextService } from './execution_context';
import type { AnalyticsServiceSetup } from './analytics';
import { AnalyticsService } from './analytics';
import { fetchOptionalMemoryInfo } from './fetch_optional_memory_info';
interface Params {

View file

@ -6,9 +6,9 @@
* Side Public License, v 1.
*/
import { BehaviorSubject, firstValueFrom } from 'rxjs';
import { analyticsServiceMock } from '@kbn/core-analytics-browser-mocks';
import type { AnalyticsServiceSetup } from '@kbn/core-analytics-browser';
import { ExecutionContextService, ExecutionContextSetup } from './execution_context_service';
import type { AnalyticsServiceSetup } from '../analytics';
import { analyticsServiceMock } from '../analytics/analytics_service.mock';
describe('ExecutionContextService', () => {
let execContext: ExecutionContextSetup;

View file

@ -9,7 +9,7 @@
import { compact, isEqual, isUndefined, omitBy } from 'lodash';
import { BehaviorSubject, Observable, Subscription, map } from 'rxjs';
import type { CoreService } from '@kbn/core-base-browser-internal';
import { AnalyticsServiceSetup } from '../analytics';
import type { AnalyticsServiceSetup } from '@kbn/core-analytics-browser';
import { KibanaExecutionContext } from '../../types';
// Should be exported from elastic/apm-rum

View file

@ -32,6 +32,7 @@ import type {
} from '@kbn/core-injected-metadata-browser';
import { DocLinksStart } from '@kbn/core-doc-links-browser';
import type { ThemeServiceSetup, ThemeServiceStart } from '@kbn/core-theme-browser';
import type { AnalyticsServiceSetup, AnalyticsServiceStart } from '@kbn/core-analytics-browser';
import {
ChromeBadge,
ChromeBreadcrumb,
@ -65,7 +66,6 @@ import { ApplicationSetup, Capabilities, ApplicationStart } from './application'
import { SavedObjectsStart } from './saved_objects';
import { DeprecationsServiceStart } from './deprecations';
import { ExecutionContextSetup, ExecutionContextStart } from './execution_context';
import type { AnalyticsServiceSetup, AnalyticsServiceStart } from './analytics';
export type {
PackageInfo,
@ -78,9 +78,8 @@ export type { CoreSystem } from './core_system';
export { DEFAULT_APP_CATEGORIES, APP_WRAPPER_CLASS } from '../utils';
export type { AppCategory, UiSettingsParams, UserProvidedValues, UiSettingsType } from '../types';
export type { AnalyticsServiceSetup, AnalyticsServiceStart } from '@kbn/core-analytics-browser';
export type {
AnalyticsServiceSetup,
AnalyticsServiceStart,
AnalyticsClient,
Event,
EventContext,
@ -91,8 +90,8 @@ export type {
OptInConfig,
ContextProviderOpts,
TelemetryCounter,
} from './analytics';
export { TelemetryCounterType } from './analytics';
} from '@kbn/analytics-client';
export { TelemetryCounterType } from '@kbn/analytics-client';
export { AppNavLinkStatus, AppStatus, ScopedHistory } from './application';
export type {

View file

@ -7,17 +7,16 @@
*/
import { createMemoryHistory } from 'history';
import type { CoreContext } from '@kbn/core-base-browser-internal';
import { injectedMetadataServiceMock } from '@kbn/core-injected-metadata-browser-mocks';
import { docLinksServiceMock } from '@kbn/core-doc-links-browser-mocks';
import { themeServiceMock } from '@kbn/core-theme-browser-mocks';
import { coreContextMock } from '@kbn/core-base-browser-mocks';
import { analyticsServiceMock } from '@kbn/core-analytics-browser-mocks';
// Only import types from '.' to avoid triggering default Jest mocks.
import { PluginInitializerContext, AppMountParameters } from '.';
// Import values from their individual modules instead.
import { ScopedHistory } from './application';
import { analyticsServiceMock } from './analytics/analytics_service.mock';
import { applicationServiceMock } from './application/application_service.mock';
import { chromeServiceMock } from './chrome/chrome_service.mock';
import { fatalErrorsServiceMock } from './fatal_errors/fatal_errors_service.mock';
@ -33,9 +32,9 @@ import { executionContextServiceMock } from './execution_context/execution_conte
export { injectedMetadataServiceMock } from '@kbn/core-injected-metadata-browser-mocks';
export { docLinksServiceMock } from '@kbn/core-doc-links-browser-mocks';
export { themeServiceMock } from '@kbn/core-theme-browser-mocks';
export { analyticsServiceMock } from '@kbn/core-analytics-browser-mocks';
export { chromeServiceMock } from './chrome/chrome_service.mock';
export { executionContextServiceMock } from './execution_context/execution_context_service.mock';
export { analyticsServiceMock } from './analytics/analytics_service.mock';
export { fatalErrorsServiceMock } from './fatal_errors/fatal_errors_service.mock';
export { httpServiceMock } from './http/http_service.mock';
export { i18nServiceMock } from './i18n/i18n_service.mock';
@ -127,26 +126,6 @@ function pluginInitializerContextMock(config: any = {}) {
return mock;
}
function createCoreContext({ production = false }: { production?: boolean } = {}): CoreContext {
return {
coreId: Symbol('core context mock'),
env: {
mode: {
dev: !production,
name: production ? 'production' : 'development',
prod: production,
},
packageInfo: {
version: 'version',
branch: 'branch',
buildNum: 100,
buildSha: 'buildSha',
dist: false,
},
},
};
}
function createStorageMock() {
const storageMock: jest.Mocked<Storage> = {
getItem: jest.fn(),
@ -178,7 +157,7 @@ function createAppMountParametersMock(appBasePath = '') {
}
export const coreMock = {
createCoreContext,
createCoreContext: coreContextMock.create,
createSetup: createCoreSetupMock,
createStart: createCoreStartMock,
createPluginInitializerContext: pluginInitializerContextMock,

View file

@ -24,6 +24,7 @@ import {
import type { InjectedMetadataPlugin } from '@kbn/core-injected-metadata-common-internal';
import { docLinksServiceMock } from '@kbn/core-doc-links-browser-mocks';
import { themeServiceMock } from '@kbn/core-theme-browser-mocks';
import { analyticsServiceMock } from '@kbn/core-analytics-browser-mocks';
import { notificationServiceMock } from '../notifications/notifications_service.mock';
import { applicationServiceMock } from '../application/application_service.mock';
import { i18nServiceMock } from '../i18n/i18n_service.mock';
@ -37,7 +38,6 @@ import { CoreSetup, CoreStart, PluginInitializerContext } from '..';
import { savedObjectsServiceMock } from '../saved_objects/saved_objects_service.mock';
import { deprecationsServiceMock } from '../deprecations/deprecations_service.mock';
import { executionContextServiceMock } from '../execution_context/execution_context_service.mock';
import { analyticsServiceMock } from '../analytics/analytics_service.mock';
export let mockPluginInitializers: Map<PluginName, MockedPluginInitializer>;

View file

@ -8,6 +8,8 @@
import { Action } from 'history';
import { AnalyticsClient } from '@kbn/analytics-client';
import { AnalyticsServiceSetup } from '@kbn/core-analytics-browser';
import { AnalyticsServiceStart } from '@kbn/core-analytics-browser';
import type { ButtonColor } from '@elastic/eui';
import { ContextProviderOpts } from '@kbn/analytics-client';
import { CoreContext } from '@kbn/core-base-browser-internal';
@ -58,15 +60,9 @@ export function __kbnBootstrap__(): Promise<void>;
export { AnalyticsClient }
// Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver
//
// @public
export type AnalyticsServiceSetup = Omit<AnalyticsClient, 'shutdown'>;
export { AnalyticsServiceSetup }
// Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver
//
// @public
export type AnalyticsServiceStart = Pick<AnalyticsClient, 'optIn' | 'reportEvent' | 'telemetryCounter$'>;
export { AnalyticsServiceStart }
// @public (undocumented)
export interface App<HistoryLocationState = unknown> extends AppNavOptions {
@ -399,6 +395,8 @@ export { CoreContext }
// @public
export interface CoreSetup<TPluginsStart extends object = object, TStart = unknown> {
// Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver
//
// (undocumented)
analytics: AnalyticsServiceSetup;
// (undocumented)
@ -427,6 +425,8 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
// @public
export interface CoreStart {
// Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver
//
// (undocumented)
analytics: AnalyticsServiceStart;
// (undocumented)

View file

@ -3015,10 +3015,26 @@
version "0.0.0"
uid ""
"@kbn/core-analytics-browser-internal@link:bazel-bin/packages/core/analytics/core-analytics-browser-internal":
version "0.0.0"
uid ""
"@kbn/core-analytics-browser-mocks@link:bazel-bin/packages/core/analytics/core-analytics-browser-mocks":
version "0.0.0"
uid ""
"@kbn/core-analytics-browser@link:bazel-bin/packages/core/analytics/core-analytics-browser":
version "0.0.0"
uid ""
"@kbn/core-base-browser-internal@link:bazel-bin/packages/core/base/core-base-browser-internal":
version "0.0.0"
uid ""
"@kbn/core-base-browser-mocks@link:bazel-bin/packages/core/base/core-base-browser-mocks":
version "0.0.0"
uid ""
"@kbn/core-base-common-internal@link:bazel-bin/packages/core/base/core-base-common-internal":
version "0.0.0"
uid ""
@ -6358,10 +6374,26 @@
version "0.0.0"
uid ""
"@types/kbn__core-analytics-browser-internal@link:bazel-bin/packages/core/analytics/core-analytics-browser-internal/npm_module_types":
version "0.0.0"
uid ""
"@types/kbn__core-analytics-browser-mocks@link:bazel-bin/packages/core/analytics/core-analytics-browser-mocks/npm_module_types":
version "0.0.0"
uid ""
"@types/kbn__core-analytics-browser@link:bazel-bin/packages/core/analytics/core-analytics-browser/npm_module_types":
version "0.0.0"
uid ""
"@types/kbn__core-base-browser-internal@link:bazel-bin/packages/core/base/core-base-browser-internal/npm_module_types":
version "0.0.0"
uid ""
"@types/kbn__core-base-browser-mocks@link:bazel-bin/packages/core/base/core-base-browser-mocks/npm_module_types":
version "0.0.0"
uid ""
"@types/kbn__core-base-browser@link:bazel-bin/packages/core/base/core-base-browser/npm_module_types":
version "0.0.0"
uid ""