Skip to content

Commit

Permalink
chore: Scaffold browser telemetry (#659)
Browse files Browse the repository at this point in the history
Scaffold the browser-telemetry project using the same build
configuration as the browser package.

In the original prototype it was done using rollup, but I would like to
generally start using this new configuration.
  • Loading branch information
kinyoklion authored Nov 7, 2024
1 parent 5fe36fb commit 37920e5
Show file tree
Hide file tree
Showing 15 changed files with 294 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .github/workflows/browser-telemetry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: telemetry/browser-telemetry

on:
push:
branches: [main, 'feat/**']
paths-ignore:
- '**.md' #Do not need to run CI for markdown changes.
pull_request:
branches: [main, 'feat/**']
paths-ignore:
- '**.md'

jobs:
build-test-browser-telemetry:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
registry-url: 'https://registry.npmjs.org'
- id: shared
name: Shared CI Steps
uses: ./actions/ci
with:
workspace_name: '@launchdarkly/browser-telemetry'
workspace_path: packages/telemetry/browser-telemetry
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"packages/sdk/browser/contract-tests/adapter",
"packages/sdk/server-ai",
"packages/sdk/server-ai/examples/bedrock",
"packages/sdk/server-ai/examples/openai"
"packages/sdk/server-ai/examples/openai",
"packages/telemetry/browser-telemetry"
],
"private": true,
"scripts": {
Expand Down
41 changes: 41 additions & 0 deletions packages/telemetry/browser-telemetry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Telemetry integration for LaunchDarkly browser SDKs.

# ⛔️⛔️⛔️⛔️

> [!WARNING]
> This is an alpha version. The API is not stabilized and will introduce breaking changes.
TODO Add badges

## LaunchDarkly overview

[LaunchDarkly](https://www.launchdarkly.com) is a feature management platform that serves over 100 billion feature flags daily to help teams build better software, faster. [Get started](https://docs.launchdarkly.com/home/getting-started) using LaunchDarkly today!

[![Twitter Follow](https://img.shields.io/twitter/follow/launchdarkly.svg?style=social&label=Follow&maxAge=2592000)](https://twitter.com/intent/follow?screen_name=launchdarkly)

## Compatibility

TODO

## Setup

TODO

## Contributing

We encourage pull requests and other contributions from the community. Check out our [contributing guidelines](CONTRIBUTING.md) for instructions on how to contribute to this SDK.

## About LaunchDarkly

- LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
- Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
- Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
- Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
- Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan).
- Disable parts of your application to facilitate maintenance, without taking everything offline.
- LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Check out [our documentation](https://docs.launchdarkly.com/sdk) for a complete list.
- Explore LaunchDarkly
- [launchdarkly.com](https://www.launchdarkly.com/ 'LaunchDarkly Main Website') for more information
- [docs.launchdarkly.com](https://docs.launchdarkly.com/ 'LaunchDarkly Documentation') for our documentation and SDK reference guides
- [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ 'LaunchDarkly API Documentation') for our API documentation
- [blog.launchdarkly.com](https://blog.launchdarkly.com/ 'LaunchDarkly Blog Documentation') for the latest product updates
4 changes: 4 additions & 0 deletions packages/telemetry/browser-telemetry/__tests__/empty.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
it('runs tests', () => {
// Placeholder so CI can run tests.
expect(true).toBeTruthy();
});
16 changes: 16 additions & 0 deletions packages/telemetry/browser-telemetry/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"verbose": true,
"testEnvironment": "jest-environment-jsdom",
"testPathIgnorePatterns": ["./dist", "./src"],
"testMatch": ["**.test.ts"],
"setupFiles": ["./setup-jest.js"],
"transform": {
"^.+\\.ts$": [
"ts-jest",
{
"tsConfig": "tsconfig.test.json"
}
],
"^.+.tsx?$": ["ts-jest", {}]
}
}
77 changes: 77 additions & 0 deletions packages/telemetry/browser-telemetry/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"name": "@launchdarkly/browser-telemetry",
"version": "0.0.9",
"packageManager": "[email protected]",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"require": {
"types": "./dist/index.d.cts",
"require": "./dist/index.cjs"
},
"import": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
}
},
"files": [
"dist"
],
"description": "Telemetry integration for LaunchDarkly browser SDKs.",
"scripts": {
"test": "npx jest --runInBand",
"build": "tsup",
"prettier": "prettier --write 'src/*.@(js|ts|tsx|json)'",
"check": "yarn && yarn prettier && yarn lint && tsc && yarn test",
"lint": "npx eslint . --ext .ts"
},
"homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/telemetry/browser-telemetry",
"repository": {
"type": "git",
"url": "git+https://github.com/launchdarkly/js-core.git"
},
"keywords": [
"launchdarkly",
"analytics",
"telemetry"
],
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/launchdarkly/js-core/issues"
},
"dependencies": {
"rrweb": "2.0.0-alpha.4",
"tracekit": "^0.4.6"
},
"peerDependencies": {
"launchdarkly-js-client-sdk": "^3.4.0"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"@types/css-font-loading-module": "^0.0.13",
"@types/jest": "^29.5.11",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"eslint": "^8.45.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.6.3",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"launchdarkly-js-test-helpers": "^2.2.0",
"prettier": "^3.0.0",
"rimraf": "^5.0.5",
"ts-jest": "^29.1.1",
"tsup": "^8.3.5",
"typedoc": "0.25.0",
"typescript": "^5.5.3"
}
}
24 changes: 24 additions & 0 deletions packages/telemetry/browser-telemetry/setup-jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { TextEncoder, TextDecoder } = require('node:util');
const crypto = require('node:crypto');

global.TextEncoder = TextEncoder;

Object.assign(window, { TextDecoder, TextEncoder });

// Based on:
// https://stackoverflow.com/a/71750830

Object.defineProperty(global.self, 'crypto', {
value: {
getRandomValues: (arr) => crypto.randomBytes(arr.length),
subtle: {
digest: (algorithm, data) => {
return new Promise((resolve) =>
resolve(
crypto.createHash(algorithm.toLowerCase().replace('-', '')).update(data).digest(),
),
);
},
},
},
});
7 changes: 7 additions & 0 deletions packages/telemetry/browser-telemetry/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Empty function for typedoc.
*/
export function empty() {
// eslint-disable-next-line no-console
console.log('Hello');
}
5 changes: 5 additions & 0 deletions packages/telemetry/browser-telemetry/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "./tsconfig.json",
"include": ["/**/*.ts", "/**/*.tsx"],
"exclude": ["node_modules"]
}
33 changes: 33 additions & 0 deletions packages/telemetry/browser-telemetry/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": true,
"declarationMap": true,
"lib": ["ES2017", "dom"],
"module": "ESNext",
"moduleResolution": "node",
"noImplicitOverride": true,
"resolveJsonModule": true,
"rootDir": ".",
"outDir": "dist",
"skipLibCheck": true,
"sourceMap": false,
"strict": true,
"stripInternal": true,
"target": "ES2017",
"types": ["node", "jest"],
"allowJs": true
},
"include": ["src"],
"exclude": [
"__tests__",
"dist",
"docs",
"example",
"node_modules",
"babel.config.js",
"setup-jest.js",
"rollup.config.js",
"**/*.test.ts*"
]
}
7 changes: 7 additions & 0 deletions packages/telemetry/browser-telemetry/tsconfig.ref.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*", "package.json", "__tests__/index.test.ts"],
"compilerOptions": {
"composite": true
}
}
27 changes: 27 additions & 0 deletions packages/telemetry/browser-telemetry/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"lib": ["es6", "DOM"],
"module": "CommonJS",
"strict": true,
"noImplicitOverride": true,
"sourceMap": true,
"declaration": true,
"declarationMap": true,
"stripInternal": true
},
"exclude": [
"vite.config.ts",
"__tests__",
"dist",
"docs",
"example",
"node_modules",
"contract-tests",
"babel.config.js",
"jest.config.js",
"jestSetupFile.ts",
"**/*.test.ts*"
]
}
16 changes: 16 additions & 0 deletions packages/telemetry/browser-telemetry/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// It is a dev dependency and the linter doesn't understand.
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineConfig } from 'tsup';

export default defineConfig({
entry: {
index: 'src/index.ts',
},
minify: true,
format: ['esm', 'cjs'],
splitting: false,
sourcemap: false,
clean: true,
dts: true,
metafile: false,
});
5 changes: 5 additions & 0 deletions packages/telemetry/browser-telemetry/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": ["../../../typedoc.base.json"],
"entryPoints": ["src/index.ts"],
"out": "docs"
}
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
},
{
"path": "./packages/sdk/server-ai/tsconfig.ref.json"
},
{
"path": "./packages/telemetry/browser-telemetry/tsconfig.ref.json"
}
]
}

0 comments on commit 37920e5

Please sign in to comment.