From b443439cb8c16e66f1a398b9fa3e486091507272 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Thu, 22 May 2025 10:53:52 -0700 Subject: [PATCH 1/9] chore: Scaffold combined browser package. --- ...ackage-sdk-combined-browser--bug_report.md | 36 +++++++++ ...e-sdk-combined-browser--feature_request.md | 19 +++++ .github/workflows/combined-browser.yml | 44 +++++++++++ .github/workflows/manual-publish-docs.yml | 1 + .github/workflows/manual-publish.yml | 1 + .github/workflows/release-please.yml | 23 +++++- .release-please-manifest.json | 3 +- package.json | 3 +- packages/sdk/combined-browser/CHANGELOG.md | 0 packages/sdk/combined-browser/LICENSE | 13 ++++ packages/sdk/combined-browser/README.md | 61 +++++++++++++++ .../combined-browser/__tests__/index.test.ts | 4 + .../sdk/combined-browser/jest.config.json | 16 ++++ packages/sdk/combined-browser/package.json | 74 +++++++++++++++++++ packages/sdk/combined-browser/setup-jest.js | 24 ++++++ packages/sdk/combined-browser/src/index.ts | 55 ++++++++++++++ .../sdk/combined-browser/tsconfig.eslint.json | 5 ++ packages/sdk/combined-browser/tsconfig.json | 35 +++++++++ .../sdk/combined-browser/tsconfig.ref.json | 7 ++ .../sdk/combined-browser/tsconfig.test.json | 27 +++++++ packages/sdk/combined-browser/tsup.config.ts | 26 +++++++ packages/sdk/combined-browser/typedoc.json | 5 ++ release-please-config.json | 4 + 23 files changed, 483 insertions(+), 3 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/package-sdk-combined-browser--bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/package-sdk-combined-browser--feature_request.md create mode 100644 .github/workflows/combined-browser.yml create mode 100644 packages/sdk/combined-browser/CHANGELOG.md create mode 100644 packages/sdk/combined-browser/LICENSE create mode 100644 packages/sdk/combined-browser/README.md create mode 100644 packages/sdk/combined-browser/__tests__/index.test.ts create mode 100644 packages/sdk/combined-browser/jest.config.json create mode 100644 packages/sdk/combined-browser/package.json create mode 100644 packages/sdk/combined-browser/setup-jest.js create mode 100644 packages/sdk/combined-browser/src/index.ts create mode 100644 packages/sdk/combined-browser/tsconfig.eslint.json create mode 100644 packages/sdk/combined-browser/tsconfig.json create mode 100644 packages/sdk/combined-browser/tsconfig.ref.json create mode 100644 packages/sdk/combined-browser/tsconfig.test.json create mode 100644 packages/sdk/combined-browser/tsup.config.ts create mode 100644 packages/sdk/combined-browser/typedoc.json diff --git a/.github/ISSUE_TEMPLATE/package-sdk-combined-browser--bug_report.md b/.github/ISSUE_TEMPLATE/package-sdk-combined-browser--bug_report.md new file mode 100644 index 0000000000..c85a1600a2 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/package-sdk-combined-browser--bug_report.md @@ -0,0 +1,36 @@ +--- +name: '@launchdarkly/browser Bug Report' +about: Create a report to help us improve +title: '' +labels: 'package: sdk/combined-browser, bug' +assignees: '' +--- + +**Is this a support request?** +This issue tracker is maintained by LaunchDarkly SDK developers and is intended for feedback on the code in this library. If you're not sure whether the problem you are having is specifically related to this library, or to the LaunchDarkly service overall, it may be more appropriate to contact the LaunchDarkly support team; they can help to investigate the problem and will consult the SDK team if necessary. You can submit a support request by going [here](https://support.launchdarkly.com/) and clicking "submit a request", or by emailing support@launchdarkly.com. + +Note that issues filed on this issue tracker are publicly accessible. Do not provide any private account information on your issues. If your problem is specific to your account, you should submit a support request as described above. + +**Describe the bug** +A clear and concise description of what the bug is. + +**To reproduce** +Steps to reproduce the behavior. + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Logs** +If applicable, add any log output related to your problem. + +**SDK version** +The version of this SDK that you are using. + +**Language version, developer tools** +For instance, Go 1.11 or Ruby 2.5.3. If you are using a language that requires a separate compiler, such as C, please include the name and version of the compiler too. + +**OS/platform** +For instance, Ubuntu 16.04, Windows 10, or Android 4.0.3. If your code is running in a browser, please also include the browser type and version. + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/package-sdk-combined-browser--feature_request.md b/.github/ISSUE_TEMPLATE/package-sdk-combined-browser--feature_request.md new file mode 100644 index 0000000000..85f7abedf7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/package-sdk-combined-browser--feature_request.md @@ -0,0 +1,19 @@ +--- +name: '@launchdarkly/browser Feature Request' +about: Create a report to help us improve +title: '' +labels: 'package: sdk/combined-browser, feature' +assignees: '' +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I would love to see the SDK [...does something new...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context about the feature request here. diff --git a/.github/workflows/combined-browser.yml b/.github/workflows/combined-browser.yml new file mode 100644 index 0000000000..3809d447ca --- /dev/null +++ b/.github/workflows/combined-browser.yml @@ -0,0 +1,44 @@ +name: sdk/combined-browser + +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: + permissions: + pull-requests: write + runs-on: ubuntu-latest + + strategy: + matrix: + # Node versions to run on. + version: [18, 21] + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.version }} + registry-url: 'https://registry.npmjs.org' + - id: shared + name: Shared CI Steps + uses: ./actions/ci + with: + workspace_name: '@launchdarkly/browser' + workspace_path: packages/sdk/combined-browser + - name: Check package size + if: github.event_name == 'pull_request' && matrix.version == '21' + uses: ./actions/package-size + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + target_file: 'packages/sdk/combined-browser/dist/index.js' + package_name: '@launchdarkly/browser' + pr_number: ${{ github.event.number }} + size_limit: 25000 diff --git a/.github/workflows/manual-publish-docs.yml b/.github/workflows/manual-publish-docs.yml index bca840c595..12608d318f 100644 --- a/.github/workflows/manual-publish-docs.yml +++ b/.github/workflows/manual-publish-docs.yml @@ -23,6 +23,7 @@ on: - packages/sdk/browser - packages/sdk/server-ai - packages/telemetry/browser-telemetry + - packages/sdk/combined-browser name: Publish Documentation jobs: build-publish: diff --git a/.github/workflows/manual-publish.yml b/.github/workflows/manual-publish.yml index e8162367c5..9a0406ceaa 100644 --- a/.github/workflows/manual-publish.yml +++ b/.github/workflows/manual-publish.yml @@ -36,6 +36,7 @@ on: - packages/sdk/browser - packages/sdk/server-ai - packages/telemetry/browser-telemetry + - packages/sdk/combined-browser prerelease: description: 'Is this a prerelease. If so, then the latest tag will not be updated in npm.' type: boolean diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index fe29d4a4dd..d8be2d4ae6 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -28,6 +28,7 @@ jobs: package-browser-released: ${{ steps.release.outputs['packages/sdk/browser--release_created'] }} package-server-ai-released: ${{ steps.release.outputs['packages/sdk/server-ai--release_created'] }} package-browser-telemetry-released: ${{ steps.release.outputs['packages/telemetry/browser-telemetry--release_created'] }} + package-combined-browser-released: ${{ steps.release.outputs['packages/sdk/combined-browser--release_created'] }} steps: - uses: googleapis/release-please-action@v4 id: release @@ -207,7 +208,7 @@ jobs: with: node-version: 22.x registry-url: 'https://registry.npmjs.org' - - id: release-react-native + - id: release-browser name: Full release of packages/sdk/browser uses: ./actions/full-release with: @@ -439,3 +440,23 @@ jobs: with: workspace_path: packages/telemetry/browser-telemetry aws_assume_role: ${{ vars.AWS_ROLE_ARN }} + + release-combined-browser: + runs-on: ubuntu-latest + needs: ['release-please', 'release-browser'] + permissions: + id-token: write + contents: write + if: ${{ always() && !failure() && !cancelled() && needs.release-please.outputs.package-combined-browser-released == 'true'}} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22.x + registry-url: 'https://registry.npmjs.org' + - id: release-combined-browser + name: Full release of packages/sdk/combined-browser + uses: ./actions/full-release + with: + workspace_path: packages/sdk/combined-browser + aws_assume_role: ${{ vars.AWS_ROLE_ARN }} diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 47cf9d905f..76144cf404 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -17,5 +17,6 @@ "packages/sdk/browser": "0.7.0", "packages/sdk/server-ai": "0.9.8", "packages/telemetry/browser-telemetry": "1.0.8", - "packages/tooling/jest": "0.1.7" + "packages/tooling/jest": "0.1.7", + "packages/sdk/combined-browser": "0.0.0" } diff --git a/package.json b/package.json index f14cbd3f7d..ce18d57b62 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,8 @@ "packages/sdk/server-ai/examples/bedrock", "packages/sdk/server-ai/examples/openai", "packages/telemetry/browser-telemetry", - "contract-tests" + "contract-tests", + "packages/sdk/combined-browser" ], "private": true, "scripts": { diff --git a/packages/sdk/combined-browser/CHANGELOG.md b/packages/sdk/combined-browser/CHANGELOG.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/sdk/combined-browser/LICENSE b/packages/sdk/combined-browser/LICENSE new file mode 100644 index 0000000000..e5c2b6985c --- /dev/null +++ b/packages/sdk/combined-browser/LICENSE @@ -0,0 +1,13 @@ +Copyright 2025 Catamorphic, Co. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/packages/sdk/combined-browser/README.md b/packages/sdk/combined-browser/README.md new file mode 100644 index 0000000000..b26aac5231 --- /dev/null +++ b/packages/sdk/combined-browser/README.md @@ -0,0 +1,61 @@ +# LaunchDarkly JavaScript SDK for Browsers + +[![NPM][browser-sdk-npm-badge]][browser-sdk-npm-link] +[![Actions Status][browser-sdk-ci-badge]][browser-sdk-ci] +[![Documentation][browser-sdk-ghp-badge]][browser-sdk-ghp-link] +[![NPM][browser-sdk-dm-badge]][browser-sdk-npm-link] +[![NPM][browser-sdk-dt-badge]][browser-sdk-npm-link] + +# ⛔️⛔️⛔️⛔️ + +> [!CAUTION] +> This library is a alpha version and should not be considered ready for production use while this message is visible. + +# ☝️☝️☝️☝️☝️☝️ + + + +## Getting started + +Refer to the [SDK documentation](https://docs.launchdarkly.com/sdk/client-side/javascript#getting-started) for instructions on getting started with using the SDK. + +Note: _If you are using JavaScript in a non-browser environment, please check our other SDK packages in [js-core](https://github.com/launchdarkly/js-core)_ +Please note that the JavaScript SDK has two special requirements in terms of your LaunchDarkly environment. First, in terms of the credentials for your environment that appear on your [Account Settings](https://app.launchdarkly.com/settings/projects) dashboard, the JavaScript SDK uses the "Client-side ID"-- not the "SDK key" or the "Mobile key". Second, for any feature flag that you will be using in JavaScript code, you must check the "Make this flag available to client-side SDKs" box on that flag's Settings page. + +## Verifying SDK build provenance with the SLSA framework + +LaunchDarkly uses the [SLSA framework](https://slsa.dev/spec/v1.0/about) (Supply-chain Levels for Software Artifacts) to help developers make their supply chain more secure by ensuring the authenticity and build integrity of our published SDK packages. To learn more, see the [provenance guide](PROVENANCE.md). + +## 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. Read [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 + +[browser-sdk-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/browser.yml/badge.svg +[browser-sdk-ci]: https://github.com/launchdarkly/js-core/actions/workflows/browser.yml +[browser-sdk-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/js-client-sdk.svg?style=flat-square +[browser-sdk-npm-link]: https://www.npmjs.com/package/@launchdarkly/js-client-sdk +[browser-sdk-ghp-badge]: https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8 +[browser-sdk-ghp-link]: https://launchdarkly.github.io/js-core/packages/sdk/browser/docs/ +[browser-sdk-dm-badge]: https://img.shields.io/npm/dm/@launchdarkly/js-client-sdk.svg?style=flat-square +[browser-sdk-dt-badge]: https://img.shields.io/npm/dt/@launchdarkly/js-client-sdk.svg?style=flat-square diff --git a/packages/sdk/combined-browser/__tests__/index.test.ts b/packages/sdk/combined-browser/__tests__/index.test.ts new file mode 100644 index 0000000000..f62dc6002c --- /dev/null +++ b/packages/sdk/combined-browser/__tests__/index.test.ts @@ -0,0 +1,4 @@ +// Placeholder test to ensure the test suite is working` +it('runs tests', () => { + expect(true).toBe(true); +}); diff --git a/packages/sdk/combined-browser/jest.config.json b/packages/sdk/combined-browser/jest.config.json new file mode 100644 index 0000000000..6d2e223cd6 --- /dev/null +++ b/packages/sdk/combined-browser/jest.config.json @@ -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", {}] + } +} diff --git a/packages/sdk/combined-browser/package.json b/packages/sdk/combined-browser/package.json new file mode 100644 index 0000000000..7296ae5ad7 --- /dev/null +++ b/packages/sdk/combined-browser/package.json @@ -0,0 +1,74 @@ +{ + "name": "@launchdarkly/browser", + "version": "0.0.0", + "description": "LaunchDarkly SDK for JavaScript in Browsers with Observability", + "homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/sdk/combined-browser", + "repository": { + "type": "git", + "url": "https://github.com/launchdarkly/js-core.git" + }, + "license": "Apache-2.0", + "packageManager": "yarn@3.4.1", + "keywords": [ + "launchdarkly", + "feature flags", + "feature toggles", + "feature management", + "sdk" + ], + "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" + ], + "scripts": { + "clean": "rimraf dist", + "build": "tsup", + "lint": "eslint . --ext .ts,.tsx", + "prettier": "prettier --write '**/*.@(js|ts|tsx|json|css)' --ignore-path ../../../.prettierignore", + "test": "npx jest --runInBand", + "coverage": "yarn test --coverage", + "check": "yarn prettier && yarn lint && yarn build && yarn test" + }, + "dependencies": { + "@launchdarkly/js-client-sdk": "0.7.0", + "@launchdarkly/observability": "0.1.13", + "@launchdarkly/session-replay": "0.1.13" + }, + "devDependencies": { + "@jest/globals": "^29.7.0", + "@trivago/prettier-plugin-sort-imports": "^4.1.1", + "@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", + "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" + } +} diff --git a/packages/sdk/combined-browser/setup-jest.js b/packages/sdk/combined-browser/setup-jest.js new file mode 100644 index 0000000000..e17ac62cb1 --- /dev/null +++ b/packages/sdk/combined-browser/setup-jest.js @@ -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(), + ), + ); + }, + }, + }, +}); diff --git a/packages/sdk/combined-browser/src/index.ts b/packages/sdk/combined-browser/src/index.ts new file mode 100644 index 0000000000..aed1ed82d6 --- /dev/null +++ b/packages/sdk/combined-browser/src/index.ts @@ -0,0 +1,55 @@ +import { initialize as initializeJsClient, LDClient, LDOptions } from '@launchdarkly/js-client-sdk'; +import Observability from '@launchdarkly/observability'; +import SessionReplay from '@launchdarkly/session-replay'; + +export * from '@launchdarkly/js-client-sdk'; + +// TODO: Temporary until the type definitions are exported from the plugins. +type ObserveOptions = ConstructorParameters[1]; +type RecordOptions = ConstructorParameters[1]; + +/** + * Initialization options for the browser SDK and observability plugins. + */ +export interface LDBrowserOptions extends LDOptions { + /** + * The project ID for observability. This is a temporary option and will be removed before the 1.0.0 release. + */ + tmpProjectId: string; + /** + * Configuration for the observability plugin. + */ + observability?: ObserveOptions; + /** + * Configuration for the session replay plugin. + */ + sessionReplay?: RecordOptions; +} + +/** + * Creates an instance of the LaunchDarkly client. The client is pre-configured for observability. + * + * Usage: + * ``` + * import { initialize } from '@launchdarkly/browser'; + * const client = initialize(clientSideId, context, options); + * ``` + * + * @param clientSideId + * The client-side ID, also known as the environment ID. + * @param options + * Optional configuration settings. + * @return + * The new client instance. + */ +export function initialize(clientSideId: string, options?: LDBrowserOptions): LDClient { + const optionsWithPlugins = { + ...options, + plugins: [ + ...(options?.plugins || []), + new Observability(options?.tmpProjectId ?? '1', options?.observability), + new SessionReplay(options?.tmpProjectId ?? '1', options?.sessionReplay), + ], + }; + return initializeJsClient(clientSideId, optionsWithPlugins); +} diff --git a/packages/sdk/combined-browser/tsconfig.eslint.json b/packages/sdk/combined-browser/tsconfig.eslint.json new file mode 100644 index 0000000000..8241f86c36 --- /dev/null +++ b/packages/sdk/combined-browser/tsconfig.eslint.json @@ -0,0 +1,5 @@ +{ + "extends": "./tsconfig.json", + "include": ["/**/*.ts", "/**/*.tsx"], + "exclude": ["node_modules"] +} diff --git a/packages/sdk/combined-browser/tsconfig.json b/packages/sdk/combined-browser/tsconfig.json new file mode 100644 index 0000000000..dcbbe20f3a --- /dev/null +++ b/packages/sdk/combined-browser/tsconfig.json @@ -0,0 +1,35 @@ +{ + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "declaration": true, + "declarationMap": true, + "lib": ["ES2017", "dom"], + "module": "ESNext", + "moduleResolution": "node", + "noImplicitOverride": true, + "resolveJsonModule": true, + "rootDir": ".", + "outDir": "dist", + "skipLibCheck": true, + "sourceMap": true, + "inlineSources": true, + "strict": true, + "stripInternal": true, + "target": "ES2017", + "types": ["node", "jest"], + "allowJs": true + }, + "include": ["src"], + "exclude": [ + "vite.config.ts", + "__tests__", + "dist", + "docs", + "example", + "node_modules", + "babel.config.js", + "setup-jest.js", + "rollup.config.js", + "**/*.test.ts*" + ] +} diff --git a/packages/sdk/combined-browser/tsconfig.ref.json b/packages/sdk/combined-browser/tsconfig.ref.json new file mode 100644 index 0000000000..3925f645be --- /dev/null +++ b/packages/sdk/combined-browser/tsconfig.ref.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "include": ["src/**/*", "package.json", "__tests__/index.test.ts"], + "compilerOptions": { + "composite": true + } +} diff --git a/packages/sdk/combined-browser/tsconfig.test.json b/packages/sdk/combined-browser/tsconfig.test.json new file mode 100644 index 0000000000..6087e302dd --- /dev/null +++ b/packages/sdk/combined-browser/tsconfig.test.json @@ -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*" + ] +} diff --git a/packages/sdk/combined-browser/tsup.config.ts b/packages/sdk/combined-browser/tsup.config.ts new file mode 100644 index 0000000000..cd2c2dbb17 --- /dev/null +++ b/packages/sdk/combined-browser/tsup.config.ts @@ -0,0 +1,26 @@ +// 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: true, + clean: true, + noExternal: ['@launchdarkly/js-sdk-common', '@launchdarkly/js-client-sdk-common'], + dts: true, + metafile: true, + esbuildOptions(opts) { + // This would normally be `^_(?!meta|_)`, but go doesn't support negative look-ahead assertions, + // so we need to craft something that works without it. + // So start of line followed by a character that isn't followed by m or underscore, but we + // want other things that do start with m, so we need to progressively handle more characters + // of meta with exclusions. + // eslint-disable-next-line no-param-reassign + opts.mangleProps = /^_([^m|_]|m[^e]|me[^t]|met[^a])/; + }, +}); diff --git a/packages/sdk/combined-browser/typedoc.json b/packages/sdk/combined-browser/typedoc.json new file mode 100644 index 0000000000..7ac616b544 --- /dev/null +++ b/packages/sdk/combined-browser/typedoc.json @@ -0,0 +1,5 @@ +{ + "extends": ["../../../typedoc.base.json"], + "entryPoints": ["src/index.ts"], + "out": "docs" +} diff --git a/release-please-config.json b/release-please-config.json index f8cbc5228c..9fc35f4bed 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -83,6 +83,10 @@ }, "packages/telemetry/browser-telemetry": {} }, + "packages/sdk/combined-browser": { + "bump-minor-pre-major": true, + "release-as": "0.0.1" + }, "plugins": [ { "type": "node-workspace", From 4a0e99f5d31ff136572ab733edcd0792ddad80b8 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Thu, 22 May 2025 13:16:45 -0700 Subject: [PATCH 2/9] Readme updates. --- packages/sdk/combined-browser/README.md | 34 ++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/sdk/combined-browser/README.md b/packages/sdk/combined-browser/README.md index b26aac5231..3e78591db6 100644 --- a/packages/sdk/combined-browser/README.md +++ b/packages/sdk/combined-browser/README.md @@ -1,10 +1,10 @@ -# LaunchDarkly JavaScript SDK for Browsers +# LaunchDarkly JavaScript SDK for Browsers with included Observability. -[![NPM][browser-sdk-npm-badge]][browser-sdk-npm-link] -[![Actions Status][browser-sdk-ci-badge]][browser-sdk-ci] -[![Documentation][browser-sdk-ghp-badge]][browser-sdk-ghp-link] -[![NPM][browser-sdk-dm-badge]][browser-sdk-npm-link] -[![NPM][browser-sdk-dt-badge]][browser-sdk-npm-link] +[![NPM][combined-browser-sdk-npm-badge]][combined-browser-sdk-npm-link] +[![Actions Status][combined-browser-sdk-ci-badge]][combined-browser-sdk-ci] +[![Documentation][combined-browser-sdk-ghp-badge]][combined-browser-sdk-ghp-link] +[![NPM][combined-browser-sdk-dm-badge]][combined-browser-sdk-npm-link] +[![NPM][combined-browser-sdk-dt-badge]][combined-browser-sdk-npm-link] # ⛔️⛔️⛔️⛔️ @@ -18,10 +18,10 @@ ```shell # npm -npm i @launchdarkly/js-client-sdk +npm i @launchdarkly/browser # yarn -yarn add -D @launchdarkly/js-client-sdk +yarn add -D @launchdarkly/browser ``` --> @@ -29,7 +29,7 @@ yarn add -D @launchdarkly/js-client-sdk Refer to the [SDK documentation](https://docs.launchdarkly.com/sdk/client-side/javascript#getting-started) for instructions on getting started with using the SDK. -Note: _If you are using JavaScript in a non-browser environment, please check our other SDK packages in [js-core](https://github.com/launchdarkly/js-core)_ +Note: _If you are using JavaScript in a non-combined-browser environment, please check our other SDK packages in [js-core](https://github.com/launchdarkly/js-core)_ Please note that the JavaScript SDK has two special requirements in terms of your LaunchDarkly environment. First, in terms of the credentials for your environment that appear on your [Account Settings](https://app.launchdarkly.com/settings/projects) dashboard, the JavaScript SDK uses the "Client-side ID"-- not the "SDK key" or the "Mobile key". Second, for any feature flag that you will be using in JavaScript code, you must check the "Make this flag available to client-side SDKs" box on that flag's Settings page. ## Verifying SDK build provenance with the SLSA framework @@ -51,11 +51,11 @@ LaunchDarkly uses the [SLSA framework](https://slsa.dev/spec/v1.0/about) (Supply - [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 -[browser-sdk-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/browser.yml/badge.svg -[browser-sdk-ci]: https://github.com/launchdarkly/js-core/actions/workflows/browser.yml -[browser-sdk-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/js-client-sdk.svg?style=flat-square -[browser-sdk-npm-link]: https://www.npmjs.com/package/@launchdarkly/js-client-sdk -[browser-sdk-ghp-badge]: https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8 -[browser-sdk-ghp-link]: https://launchdarkly.github.io/js-core/packages/sdk/browser/docs/ -[browser-sdk-dm-badge]: https://img.shields.io/npm/dm/@launchdarkly/js-client-sdk.svg?style=flat-square -[browser-sdk-dt-badge]: https://img.shields.io/npm/dt/@launchdarkly/js-client-sdk.svg?style=flat-square +[combined-browser-sdk-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/combined-browser.yml/badge.svg +[combined-browser-sdk-ci]: https://github.com/launchdarkly/js-core/actions/workflows/combined-browser.yml +[combined-browser-sdk-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/browser.svg?style=flat-square +[combined-browser-sdk-npm-link]: https://www.npmjs.com/package/@launchdarkly/browser +[combined-browser-sdk-ghp-badge]: https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8 +[combined-browser-sdk-ghp-link]: https://launchdarkly.github.io/js-core/packages/sdk/combined-browser/docs/ +[combined-browser-sdk-dm-badge]: https://img.shields.io/npm/dm/@launchdarkly/browser.svg?style=flat-square +[combined-browser-sdk-dt-badge]: https://img.shields.io/npm/dt/@launchdarkly/browser.svg?style=flat-square From 423fd0d69d101cbe7cf407eeacb9751f641b3480 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Thu, 22 May 2025 13:30:23 -0700 Subject: [PATCH 3/9] Bundle. --- packages/sdk/combined-browser/src/index.ts | 15 +++++++++++++++ packages/sdk/combined-browser/tsup.config.ts | 8 +++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/sdk/combined-browser/src/index.ts b/packages/sdk/combined-browser/src/index.ts index aed1ed82d6..a73d4f562b 100644 --- a/packages/sdk/combined-browser/src/index.ts +++ b/packages/sdk/combined-browser/src/index.ts @@ -1,3 +1,15 @@ +/** + * This is the API reference for the LaunchDarkly Client-Side SDK for JavaScript with included Observability. + * + * This SDK is intended for use in browser environments. It includes the observability and session replay plugins. + * + * In typical usage, you will call {@link initialize} once at startup time to obtain an instance of + * {@link LDClient}, which provides access to all of the SDK's functionality. + * + * For more information, see the [SDK Reference Guide](https://docs.launchdarkly.com/sdk/client-side/javascript). + * + * @packageDocumentation + */ import { initialize as initializeJsClient, LDClient, LDOptions } from '@launchdarkly/js-client-sdk'; import Observability from '@launchdarkly/observability'; import SessionReplay from '@launchdarkly/session-replay'; @@ -8,6 +20,9 @@ export * from '@launchdarkly/js-client-sdk'; type ObserveOptions = ConstructorParameters[1]; type RecordOptions = ConstructorParameters[1]; +export { LDObserve } from '@launchdarkly/observability'; +export { LDRecord } from '@launchdarkly/session-replay'; + /** * Initialization options for the browser SDK and observability plugins. */ diff --git a/packages/sdk/combined-browser/tsup.config.ts b/packages/sdk/combined-browser/tsup.config.ts index cd2c2dbb17..f863d12e41 100644 --- a/packages/sdk/combined-browser/tsup.config.ts +++ b/packages/sdk/combined-browser/tsup.config.ts @@ -11,7 +11,13 @@ export default defineConfig({ splitting: false, sourcemap: true, clean: true, - noExternal: ['@launchdarkly/js-sdk-common', '@launchdarkly/js-client-sdk-common'], + noExternal: [ + '@launchdarkly/js-sdk-common', + '@launchdarkly/js-client-sdk-common', + '@launchdarkly/observability', + '@launchdarkly/session-replay', + '@launchdarkly/js-client-sdk', + ], dts: true, metafile: true, esbuildOptions(opts) { From e5aac90eab2aabdca245418c92c47c22b8bdb88e Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Thu, 22 May 2025 13:39:15 -0700 Subject: [PATCH 4/9] Root tsconfug update. --- tsconfig.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index f1fcd6a232..bd2b4db44a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -75,6 +75,9 @@ }, { "path": "./contract-tests/tsconfig.ref.json" - } + }, + { + "path": "./packages/sdk/combined-browser/tsconfig.ref.json" + }, ] } From 410059f6ef320662d9dec613f24f78193ebb2c4f Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Thu, 22 May 2025 13:41:38 -0700 Subject: [PATCH 5/9] Set a reasonable size limit. --- .github/workflows/combined-browser.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/combined-browser.yml b/.github/workflows/combined-browser.yml index 3809d447ca..7c6860d0ad 100644 --- a/.github/workflows/combined-browser.yml +++ b/.github/workflows/combined-browser.yml @@ -41,4 +41,4 @@ jobs: target_file: 'packages/sdk/combined-browser/dist/index.js' package_name: '@launchdarkly/browser' pr_number: ${{ github.event.number }} - size_limit: 25000 + size_limit: 200000 From 82c3756d192fc33c95992d6250f20f1d1e898a58 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Thu, 22 May 2025 14:07:08 -0700 Subject: [PATCH 6/9] Top level readme --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 2881b7f8ee..cd4640185e 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ This includes shared libraries, used by SDKs and other tools, as well as SDKs. | [@launchdarkly/react-native-client-sdk](packages/sdk/react-native/README.md) | [![NPM][sdk-react-native-npm-badge]][sdk-react-native-npm-link] | [React-Native][package-sdk-react-native-issues] | [![Actions Status][sdk-react-native-ci-badge]][sdk-react-native-ci] | | [@launchdarkly/js-client-sdk](packages/sdk/browser/README.md) | [![NPM][sdk-browser-npm-badge]][sdk-browser-npm-link] | [Browser][package-sdk-browser-issues] | [![Actions Status][sdk-browser-ci-badge]][sdk-browser-ci] | | [@launchdarkly/server-sdk-ai](packages/sdk/server-ai/README.md) | [![NPM][sdk-server-ai-npm-badge]][sdk-server-ai-npm-link] | [server-ai][package-sdk-server-ai-issues] | [![Actions Status][sdk-server-ai-ci-badge]][sdk-server-ai-ci] | + | Shared packages | npm | issues | tests | | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------- | @@ -209,3 +210,13 @@ We encourage pull requests and other contributions from the community. Check out [browser-telemetry-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/browser-telemetry.svg?style=flat-square [browser-telemetry-npm-link]: https://www.npmjs.com/package/@launchdarkly/browser-telemetry [browser-telemetry-issues]: https://github.com/launchdarkly/js-core/issues?q=is%3Aissue+is%3Aopen+label%3A%22package%3A+telemetry%2Fbrowser-telemetry%22+ +[//]: # 'sdk/combined-browser' +[sdk-browser-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/combined-browser.yml/badge.svg +[sdk-browser-ci]: https://github.com/launchdarkly/js-core/actions/workflows/combined-browser.yml +[sdk-browser-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/browser.svg?style=flat-square +[sdk-browser-npm-link]: https://www.npmjs.com/package/@launchdarkly/browser +[sdk-browser-ghp-badge]: https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8 +[sdk-browser-ghp-link]: https://launchdarkly.github.io/js-core/packages/sdk/combined-browser/docs/ +[sdk-browser-dm-badge]: https://img.shields.io/npm/dm/@launchdarkly/browser.svg?style=flat-square +[sdk-browser-dt-badge]: https://img.shields.io/npm/dt/@launchdarkly/browser.svg?style=flat-square +[package-sdk-browser-issues]: https://github.com/launchdarkly/js-core/issues?q=is%3Aissue+is%3Aopen+label%3A%22package%3A+sdk%2Fcombined-browser%22+ \ No newline at end of file From 00460356e90931bacf653b1f72ac5a2d45ddec77 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Wed, 4 Jun 2025 15:30:32 -0700 Subject: [PATCH 7/9] Update package versions. --- packages/sdk/combined-browser/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/sdk/combined-browser/package.json b/packages/sdk/combined-browser/package.json index 7296ae5ad7..c68af3b5db 100644 --- a/packages/sdk/combined-browser/package.json +++ b/packages/sdk/combined-browser/package.json @@ -46,8 +46,8 @@ }, "dependencies": { "@launchdarkly/js-client-sdk": "0.7.0", - "@launchdarkly/observability": "0.1.13", - "@launchdarkly/session-replay": "0.1.13" + "@launchdarkly/observability": "0.2.0", + "@launchdarkly/session-replay": "0.2.0" }, "devDependencies": { "@jest/globals": "^29.7.0", From 0c63e9f56f25ef549e54ac96b241d46630970d06 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Wed, 4 Jun 2025 15:32:14 -0700 Subject: [PATCH 8/9] Remove temporary export code. --- packages/sdk/combined-browser/src/index.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/sdk/combined-browser/src/index.ts b/packages/sdk/combined-browser/src/index.ts index a73d4f562b..59b4c0d782 100644 --- a/packages/sdk/combined-browser/src/index.ts +++ b/packages/sdk/combined-browser/src/index.ts @@ -11,17 +11,13 @@ * @packageDocumentation */ import { initialize as initializeJsClient, LDClient, LDOptions } from '@launchdarkly/js-client-sdk'; -import Observability from '@launchdarkly/observability'; -import SessionReplay from '@launchdarkly/session-replay'; +import Observability, { ObserveOptions } from '@launchdarkly/observability'; +import SessionReplay, { RecordOptions } from '@launchdarkly/session-replay'; export * from '@launchdarkly/js-client-sdk'; -// TODO: Temporary until the type definitions are exported from the plugins. -type ObserveOptions = ConstructorParameters[1]; -type RecordOptions = ConstructorParameters[1]; - -export { LDObserve } from '@launchdarkly/observability'; -export { LDRecord } from '@launchdarkly/session-replay'; +export { LDObserve, ObserveOptions } from '@launchdarkly/observability'; +export { LDRecord, RecordOptions } from '@launchdarkly/session-replay'; /** * Initialization options for the browser SDK and observability plugins. From d38facddcb9e167122db55a3cb999137a26f7180 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Wed, 4 Jun 2025 15:33:46 -0700 Subject: [PATCH 9/9] Update readme names. --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index cd4640185e..ee16a1860e 100644 --- a/README.md +++ b/README.md @@ -211,12 +211,12 @@ We encourage pull requests and other contributions from the community. Check out [browser-telemetry-npm-link]: https://www.npmjs.com/package/@launchdarkly/browser-telemetry [browser-telemetry-issues]: https://github.com/launchdarkly/js-core/issues?q=is%3Aissue+is%3Aopen+label%3A%22package%3A+telemetry%2Fbrowser-telemetry%22+ [//]: # 'sdk/combined-browser' -[sdk-browser-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/combined-browser.yml/badge.svg -[sdk-browser-ci]: https://github.com/launchdarkly/js-core/actions/workflows/combined-browser.yml -[sdk-browser-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/browser.svg?style=flat-square -[sdk-browser-npm-link]: https://www.npmjs.com/package/@launchdarkly/browser -[sdk-browser-ghp-badge]: https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8 -[sdk-browser-ghp-link]: https://launchdarkly.github.io/js-core/packages/sdk/combined-browser/docs/ -[sdk-browser-dm-badge]: https://img.shields.io/npm/dm/@launchdarkly/browser.svg?style=flat-square -[sdk-browser-dt-badge]: https://img.shields.io/npm/dt/@launchdarkly/browser.svg?style=flat-square +[sdk-combined-browser-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/combined-browser.yml/badge.svg +[sdk-combined-browser-ci]: https://github.com/launchdarkly/js-core/actions/workflows/combined-browser.yml +[sdk-combined-browser-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/browser.svg?style=flat-square +[sdk-combined-browser-npm-link]: https://www.npmjs.com/package/@launchdarkly/browser +[sdk-combined-browser-ghp-badge]: https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8 +[sdk-combined-browser-ghp-link]: https://launchdarkly.github.io/js-core/packages/sdk/combined-browser/docs/ +[sdk-combined-browser-dm-badge]: https://img.shields.io/npm/dm/@launchdarkly/browser.svg?style=flat-square +[sdk-combined-browser-dt-badge]: https://img.shields.io/npm/dt/@launchdarkly/browser.svg?style=flat-square [package-sdk-browser-issues]: https://github.com/launchdarkly/js-core/issues?q=is%3Aissue+is%3Aopen+label%3A%22package%3A+sdk%2Fcombined-browser%22+ \ No newline at end of file