-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/142958
- Loading branch information
Showing
144 changed files
with
5,609 additions
and
429 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
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 = "gainsight" | ||
PKG_REQUIRE_NAME = "@kbn/analytics-shippers-gainsight" | ||
|
||
SOURCE_FILES = glob( | ||
[ | ||
"**/*.ts", | ||
], | ||
exclude = [ | ||
"**/*.config.js", | ||
"**/*.mock.*", | ||
"**/*.test.*", | ||
"**/*.stories.*", | ||
"**/__snapshots__/**", | ||
"**/integration_tests/**", | ||
"**/mocks/**", | ||
"**/scripts/**", | ||
"**/storybook/**", | ||
"**/test_fixtures/**", | ||
"**/test_helpers/**", | ||
], | ||
) | ||
|
||
SRCS = SOURCE_FILES | ||
|
||
filegroup( | ||
name = "srcs", | ||
srcs = SRCS, | ||
) | ||
|
||
NPM_MODULE_EXTRA_FILES = [ | ||
"package.json", | ||
] | ||
|
||
# In this array place runtime dependencies, including other packages and NPM packages | ||
# which must be available for this code to run. | ||
# | ||
# To reference other packages use: | ||
# "//repo/relative/path/to/package" | ||
# eg. "//packages/kbn-utils" | ||
# | ||
# To reference a NPM package use: | ||
# "@npm//name-of-package" | ||
# eg. "@npm//lodash" | ||
RUNTIME_DEPS = [ | ||
"@npm//moment", | ||
] | ||
|
||
# In this array place dependencies necessary to build the types, which will include the | ||
# :npm_module_types target of other packages and packages from NPM, including @types/* | ||
# packages. | ||
# | ||
# To reference the types for another package use: | ||
# "//repo/relative/path/to/package:npm_module_types" | ||
# eg. "//packages/kbn-utils:npm_module_types" | ||
# | ||
# References to NPM packages work the same as RUNTIME_DEPS | ||
TYPES_DEPS = [ | ||
"@npm//@types/node", | ||
"@npm//@types/jest", | ||
"@npm//moment", | ||
"//packages/analytics/client:npm_module_types", | ||
"//packages/kbn-logging-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, | ||
declaration_map = True, | ||
emit_declaration_only = True, | ||
out_dir = "target_types", | ||
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"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# @kbn/analytics-shippers-gainsight | ||
|
||
gainsight implementation as a shipper for the `@kbn/analytics-client`. | ||
|
||
## How to use it | ||
|
||
This module is intended to be used **on the browser only**. It does not support server-side events. | ||
|
||
```typescript | ||
import { GainsightShipper } from "@kbn/analytics-shippers-gainsight"; | ||
|
||
analytics.registerShipper(GainsightShipper, { gainsightOrgId: '12345' }) | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { GainsightShipper } from './src/gainsight_shipper'; | ||
export type { GainsightSnippetConfig } from './src/load_snippet'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/jest_node', | ||
rootDir: '../../../../', | ||
roots: ['<rootDir>/packages/analytics/shippers/gainsight'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "shared-browser", | ||
"id": "@kbn/analytics-shippers-gainsight", | ||
"owner": "@elastic/kibana-core", | ||
"runtimeDeps": [], | ||
"typeDeps": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "@kbn/analytics-shippers-gainsight", | ||
"private": true, | ||
"version": "1.0.0", | ||
"browser": "./target_web/index.js", | ||
"main": "./target_node/index.js", | ||
"author": "Kibana Core", | ||
"license": "SSPL-1.0 OR Elastic License 2.0" | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/analytics/shippers/gainsight/src/gainsight_shipper.test.mocks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* 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 { GainsightApi } from './types'; | ||
|
||
export const gainsightApiMock: GainsightApi = jest.fn(); | ||
gainsightApiMock.init = true; | ||
|
||
jest.doMock('./load_snippet', () => { | ||
return { | ||
loadSnippet: () => gainsightApiMock, | ||
}; | ||
}); |
102 changes: 102 additions & 0 deletions
102
packages/analytics/shippers/gainsight/src/gainsight_shipper.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* 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 { loggerMock } from '@kbn/logging-mocks'; | ||
import { gainsightApiMock } from './gainsight_shipper.test.mocks'; | ||
import { GainsightShipper } from './gainsight_shipper'; | ||
|
||
describe('gainsightShipper', () => { | ||
let gainsightShipper: GainsightShipper; | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
gainsightShipper = new GainsightShipper( | ||
{ | ||
gainsightOrgId: 'test-org-id', | ||
}, | ||
{ | ||
logger: loggerMock.create(), | ||
sendTo: 'staging', | ||
isDev: true, | ||
} | ||
); | ||
}); | ||
|
||
describe('extendContext', () => { | ||
describe('identify', () => { | ||
test('calls `identify` when the clusterName is provided', () => { | ||
const userId = 'test-user-id'; | ||
const clusterName = '123654'; | ||
gainsightShipper.extendContext({ userId, cluster_name: clusterName }); | ||
expect(gainsightApiMock).toHaveBeenCalledWith('identify', { | ||
id: clusterName, | ||
userType: 'deployment', | ||
}); | ||
}); | ||
|
||
test('calls `identify` again only if the clusterName changes', () => { | ||
const userId = 'test-user-id'; | ||
const clusterName = '123654'; | ||
gainsightShipper.extendContext({ userId, cluster_name: clusterName }); | ||
expect(gainsightApiMock).toHaveBeenCalledTimes(2); | ||
expect(gainsightApiMock).toHaveBeenCalledWith('identify', { | ||
id: clusterName, | ||
userType: 'deployment', | ||
}); | ||
expect(gainsightApiMock).toHaveBeenCalledWith('set', 'globalContext', { | ||
kibanaUserId: userId, | ||
}); | ||
|
||
gainsightShipper.extendContext({ userId, cluster_name: clusterName }); | ||
expect(gainsightApiMock).toHaveBeenCalledTimes(3); | ||
|
||
gainsightShipper.extendContext({ userId, cluster_name: `${clusterName}-1` }); | ||
expect(gainsightApiMock).toHaveBeenCalledTimes(5); // called again because the user changed | ||
}); | ||
}); | ||
}); | ||
|
||
describe('optIn', () => { | ||
test('should call consent true and restart when isOptIn: true', () => { | ||
gainsightShipper.optIn(true); | ||
expect(gainsightApiMock).toHaveBeenCalledWith('config', 'enableTag', true); | ||
}); | ||
|
||
test('should call consent false and shutdown when isOptIn: false', () => { | ||
gainsightShipper.optIn(false); | ||
expect(gainsightApiMock).toHaveBeenCalledWith('config', 'enableTag', false); | ||
}); | ||
}); | ||
|
||
describe('reportEvents', () => { | ||
test('calls the API once per event in the array with the properties transformed', () => { | ||
gainsightShipper.reportEvents([ | ||
{ | ||
event_type: 'test-event-1', | ||
timestamp: '2020-01-01T00:00:00.000Z', | ||
properties: { test: 'test-1' }, | ||
context: { pageName: 'test-page-1' }, | ||
}, | ||
{ | ||
event_type: 'test-event-2', | ||
timestamp: '2020-01-01T00:00:00.000Z', | ||
properties: { other_property: 'test-2' }, | ||
context: { pageName: 'test-page-1' }, | ||
}, | ||
]); | ||
|
||
expect(gainsightApiMock).toHaveBeenCalledTimes(2); | ||
expect(gainsightApiMock).toHaveBeenCalledWith('track', 'test-event-1', { | ||
test: 'test-1', | ||
}); | ||
expect(gainsightApiMock).toHaveBeenCalledWith('track', 'test-event-2', { | ||
other_property: 'test-2', | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.