From cb1643f1299081990b35af9c28feca0ac68be3dd Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:37:09 -0700 Subject: [PATCH 1/4] chore: Migrate to github actions and release-please. --- .github/actions/publish-docs/action.yml | 16 +++++++ .github/actions/publish-npm/action.yml | 20 +++++++++ .github/workflows/ci.yml | 39 +++++++++++++++++ .github/workflows/lint-pr-title.yml | 12 ++++++ .github/workflows/release-please.yml | 57 +++++++++++++++++++++++++ .release-please-manifest.json | 3 ++ docs/Makefile | 28 ------------ docs/doc.md | 7 --- docs/tsconfig.json | 12 ------ docs/typedoc.js | 17 -------- package.json | 7 +-- release-please-config.json | 10 +++++ scripts/publish-npm.sh | 11 +++++ typedoc.json | 17 ++++++++ typings.d.ts | 39 ++++++++++------- 15 files changed, 213 insertions(+), 82 deletions(-) create mode 100644 .github/actions/publish-docs/action.yml create mode 100644 .github/actions/publish-npm/action.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/lint-pr-title.yml create mode 100644 .github/workflows/release-please.yml create mode 100644 .release-please-manifest.json delete mode 100644 docs/Makefile delete mode 100644 docs/doc.md delete mode 100644 docs/tsconfig.json delete mode 100644 docs/typedoc.js create mode 100644 release-please-config.json create mode 100755 scripts/publish-npm.sh create mode 100644 typedoc.json diff --git a/.github/actions/publish-docs/action.yml b/.github/actions/publish-docs/action.yml new file mode 100644 index 0000000..6b5e418 --- /dev/null +++ b/.github/actions/publish-docs/action.yml @@ -0,0 +1,16 @@ +name: Publish Documentation +description: 'Publish documentation to github pages.' + +inputs: + github_token: + description: 'The github token to use for committing' + required: true + +runs: + using: composite + steps: + - uses: launchdarkly/gh-actions/actions/publish-pages@publish-pages-v1.0.2 + name: 'Publish to Github pages' + with: + docs_path: docs + github_token: ${{ inputs.github_token }} diff --git a/.github/actions/publish-npm/action.yml b/.github/actions/publish-npm/action.yml new file mode 100644 index 0000000..92fed56 --- /dev/null +++ b/.github/actions/publish-npm/action.yml @@ -0,0 +1,20 @@ +name: Publish to NPM +description: Publish an npm package. +inputs: + prerelease: + description: 'Is this a prerelease. If so, then the latest tag will not be updated in npm.' + required: false + dry-run: + description: 'Is this a dry run. If so no package will be published.' + required: false + +runs: + using: composite + steps: + - name: Publish + shell: bash + run: | + ./scripts/publish-npm.sh + env: + LD_RELEASE_IS_PRERELEASE: ${{ inputs.prerelease }} + LD_RELEASE_IS_DRYRUN: ${{ inputs.dry-run }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c6c5d82 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +name: Build and Test + +on: + push: + branches: [main] + paths-ignore: + - '**.md' #Do not need to run CI for markdown changes. + pull_request: + branches: [main] + paths-ignore: + - '**.md' + +jobs: + build-test: + strategy: + matrix: + variations: [ + {os: ubuntu-latest, node: latest}, + {os: ubuntu-latest, node: 18} + ] + + runs-on: ${{ matrix.variations.os }} + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.variations.node }} + registry-url: 'https://registry.npmjs.org' + - name: Install + run: npm install + - name: Test + run: npm test + - name: Lint + run: npm run lint:all + - name: Check typescript + run: npm run check-typescript + - name: Build Docs + run: npm run doc diff --git a/.github/workflows/lint-pr-title.yml b/.github/workflows/lint-pr-title.yml new file mode 100644 index 0000000..4ba79c1 --- /dev/null +++ b/.github/workflows/lint-pr-title.yml @@ -0,0 +1,12 @@ +name: Lint PR title + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +jobs: + lint-pr-title: + uses: launchdarkly/gh-actions/.github/workflows/lint-pr-title.yml@main diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 0000000..214f657 --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,57 @@ +name: Release Please + +on: + push: + branches: + - main + +jobs: + release-please: + runs-on: ubuntu-latest + outputs: + release_created: ${{ steps.release.outputs.release_created }} + steps: + - uses: googleapis/release-please-action@v4 + id: release + with: + token: ${{secrets.GITHUB_TOKEN}} + + publish-package: + runs-on: ubuntu-latest + needs: ['release-please'] + permissions: + id-token: write + contents: write + if: ${{ needs.release-please.outputs.release_created == 'true' }} + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 20.x + registry-url: 'https://registry.npmjs.org' + + - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets-v1.2.0 + name: 'Get NPM token' + with: + aws_assume_role: ${{ vars.AWS_ROLE_ARN }} + ssm_parameter_pairs: '/production/common/releasing/npm/token = NODE_AUTH_TOKEN' + + - name: Install Dependencies + run: npm install + + - id: publish-npm + name: Publish NPM Package + uses: ./.github/actions/publish-npm + with: + dry-run: 'false' + prerelease: 'false' + + - name: Build Documentation + run: npm run doc + + - id: publish-docs + name: Publish Documentation + uses: ./.github/actions/publish-docs + with: + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..a3b1e29 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "3.2.1" +} diff --git a/docs/Makefile b/docs/Makefile deleted file mode 100644 index e261f54..0000000 --- a/docs/Makefile +++ /dev/null @@ -1,28 +0,0 @@ - -# The TypeDoc build for this module is more complicated than for ldclient-node because it takes some of -# its types from launchdarkly-js-sdk-common. TypeDoc unfortunately does not understand the directive -# "export * from 'launchdarkly-js-sdk-common'" - so, by default, even though it does see the common types (like -# LDUser), it will not include them in the output. -# -# The current solution is to run TypeDoc on a hacked-together file that puts all of the types directly -# into one package. The sed commands below create this temporary declaration file by taking our types file -# and replacing the launchdarkly-js-sdk-common imports with the actual contents of the launchdarkly-js-sdk-common module. -# We then run TypeDoc from the docs directory, which contains its own tsconfig.json that points to the -# temporarily file instead of the original files. -# - -.PHONY: html prepare - -html: prepare - ../node_modules/.bin/typedoc --options typedoc.js - -prepare: - rm -rf build - mkdir build - @# Extract the whole module declaration from launchdarkly-js-sdk-common, then remove the first and last lines - sed -n '/^declare module/,/^}/p' ../node_modules/launchdarkly-js-sdk-common/typings.d.ts | \ - sed '1d;$$d' \ - >build/common-excerpt - @# Replace the block from DOCBUILD-START-REPLACE to DOCBUILD-END-REPLACE with that excerpt - sed -e '/DOCBUILD-END-REPLACE/r build/common-excerpt' ../typings.d.ts | \ - sed -e '/DOCBUILD-START-REPLACE/,/DOCBUILD-END-REPLACE/d' >build/typings.d.ts diff --git a/docs/doc.md b/docs/doc.md deleted file mode 100644 index 6d95e62..0000000 --- a/docs/doc.md +++ /dev/null @@ -1,7 +0,0 @@ - This is the API reference for the LaunchDarkly Client-Side Node SDK. - - In typical usage, you will call [[initialize]] in the main process at startup time to obtain an - an instance of [[LDClient]]. - - For more information, see the [SDK reference guide](https://docs.launchdarkly.com/sdk/client-side/node-js). - \ No newline at end of file diff --git a/docs/tsconfig.json b/docs/tsconfig.json deleted file mode 100644 index 9374e16..0000000 --- a/docs/tsconfig.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "strict": true, - "lib": [ - "es6" - ] - }, - "files": [ - "build/typings.d.ts" - ] -} diff --git a/docs/typedoc.js b/docs/typedoc.js deleted file mode 100644 index aae6d20..0000000 --- a/docs/typedoc.js +++ /dev/null @@ -1,17 +0,0 @@ -// Note that the format of this file is barely documented on the TypeDoc site. In general, -// the properties are equivalent to the command-line options described here: -// https://typedoc.org/api/ - -let version = process.env.VERSION; -if (!version) { - const package = require('../package.json'); - version = package.version; -} - -module.exports = { - out: './build/html', - name: 'LaunchDarkly Client-Side Node SDK (' + version + ')', - readme: 'doc.md', - entryPointStrategy: 'resolve', // Allows us to specify the specific entrypoints. - entryPoints: ["./build/typings.d.ts"] // This is the updated version created by the makefile. -}; diff --git a/package.json b/package.json index d013c3b..41aeb96 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "check-typescript": "node_modules/typescript/bin/tsc", "contract-test-service": "npm --prefix contract-tests install && npm --prefix contract-tests start", "contract-test-harness": "curl -s https://raw.githubusercontent.com/launchdarkly/sdk-test-harness/main/downloader/run.sh \\ | VERSION=v2 PARAMS=\"-url http://localhost:8000 -debug -stop-service-at-end $TEST_HARNESS_PARAMS\" sh", - "contract-tests": "npm run contract-test-service & npm run contract-test-harness" + "contract-tests": "npm run contract-test-service & npm run contract-test-harness", + "doc": "typedoc" }, "engines": { "node": ">= 12.0.0" @@ -40,8 +41,8 @@ "jest-junit": "^14.0.1", "launchdarkly-js-test-helpers": "1.2.1", "prettier": "2.7.1", - "typescript": "^4.8.4", - "typedoc": "^0.23.24" + "typescript": "~5.4.5", + "typedoc": "^0.25.13" }, "jest": { "rootDir": "src", diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..fbe79f0 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,10 @@ +{ + "bootstrap-sha": "aef46172aa8ae518d18e456f573e35bec8f542b0", + "packages": { + ".": { + "release-type": "node", + "include-v-in-tag": false, + "include-component-in-tag": false + } + } +} diff --git a/scripts/publish-npm.sh b/scripts/publish-npm.sh new file mode 100755 index 0000000..69196bd --- /dev/null +++ b/scripts/publish-npm.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +if $LD_RELEASE_IS_DRYRUN ; then + echo "Doing a dry run of publishing." +else + if $LD_RELEASE_IS_PRERELEASE ; then + echo "Publishing with prerelease tag." + npm publish --tag prerelease --provenance --access public || { echo "npm publish failed" >&2; exit 1; } + else + npm publish --provenance --access public || { echo "npm publish failed" >&2; exit 1; } + fi +fi diff --git a/typedoc.json b/typedoc.json new file mode 100644 index 0000000..1424d7b --- /dev/null +++ b/typedoc.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://typedoc.org/schema.json", + "name": "launchdarkly-node-client-sdk", + "includeVersion": true, + "entryPoints": [ + "typings.d.ts", + ], + "readme": "none", + "visibilityFilters": { + "protected": false, + "private": false, + "inherited": true, + "external": true, + "@alpha": false, + "@beta": false + } +} diff --git a/typings.d.ts b/typings.d.ts index 19260dd..27b4b2a 100644 --- a/typings.d.ts +++ b/typings.d.ts @@ -1,6 +1,16 @@ -declare module 'launchdarkly-node-client-sdk' { +/** +* This is the API reference for the LaunchDarkly Client-Side Node SDK. +* +* +* 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/node-js). +* +* @packageDocumentation +*/ -//// DOCBUILD-START-REPLACE (see docs/Makefile) +declare module 'launchdarkly-node-client-sdk' { export * from 'launchdarkly-js-sdk-common'; import { @@ -14,7 +24,6 @@ declare module 'launchdarkly-node-client-sdk' { LDOptionsBase, LDContext } from 'launchdarkly-js-sdk-common'; -//// DOCBUILD-END-REPLACE /** * The current version string of the SDK. @@ -26,13 +35,13 @@ declare module 'launchdarkly-node-client-sdk' { * * Applications should instantiate a single instance for the lifetime of the application. * The client will begin attempting to connect to LaunchDarkly as soon as it is created. To - * determine when it is ready to use, call [[LDClient.waitForInitialization]], or register an - * event listener for the `"ready"` event using [[LDClient.on]]. + * determine when it is ready to use, call {@link LDClient.waitForInitialization}, or register an + * event listener for the `"ready"` event using {@link LDClient.on}. * * @param envKey * The LaunchDarkly environment ID. * @param context - * The initial context properties. These can be changed later with [[LDClient.identify]]. + * The initial context properties. These can be changed later with {@link LDClient.identify}. * The context must have a `key` property, except that if you omit `context.key` and set `context.anonymous` to * true, the SDK will create a randomized unique key (which will be cached in local storage for the * current OS user account, so the next initialization will reuse the same key). @@ -61,8 +70,8 @@ declare module 'launchdarkly-node-client-sdk' { /** * Additional parameters to pass to the Node HTTPS API for secure requests. These can include any * of the TLS-related parameters supported by `https.request()`, such as `ca`, `cert`, and `key`. - * This object should be stored in the `tlsParams` property of [[LDOptions]]. - * + * This object should be stored in the `tlsParams` property of {@link LDOptions}. + * * For more information, see the Node documentation for `https.request()` and `tls.connect()`. */ export interface LDTLSOptions { @@ -81,7 +90,7 @@ declare module 'launchdarkly-node-client-sdk' { /** * The LaunchDarkly SDK client object. * - * Applications should configure the client at startup time with [[initialize]], and reuse the same instance. + * Applications should configure the client at startup time with {@link initialize}, and reuse the same instance. * * For more information, see the [SDK Reference Guide](https://docs.launchdarkly.com/sdk/client-side/node-js). */ @@ -89,19 +98,19 @@ declare module 'launchdarkly-node-client-sdk' { } /** - * Provides a simple [[LDLogger]] implementation. + * Provides a simple {@link LDLogger} implementation. * * This logging implementation uses a simple format that includes only the log level * and the message text. Output is written to the standard error stream (`console.error`). - * You can filter by log level as described in [[BasicLoggerOptions.level]]. + * You can filter by log level as described in {@link BasicLoggerOptions.level}. * - * To use the logger created by this function, put it into [[LDOptions.logger]]. If - * you do not set [[LDOptions.logger]] to anything, the SDK uses a default logger + * To use the logger created by this function, put it into {@link LDOptions.logger}. If + * you do not set {@link LDOptions.logger} to anything, the SDK uses a default logger * that is equivalent to `ld.basicLogger({ level: 'info' })`. * * @param options Configuration for the logger. If no options are specified, the * logger uses `{ level: 'info' }`. - * + * * @example * This example shows how to use `basicLogger` in your SDK options to enable console * logging only at `warn` and `error` levels. @@ -120,7 +129,7 @@ declare module 'launchdarkly-node-client-sdk' { * }; * ``` */ - export function basicLogger( + export function basicLogger( options?: BasicLoggerOptions ): LDLogger; } From 658606d7b6fe2000cdf8845bb84e7a3c6822e791 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:42:54 -0700 Subject: [PATCH 2/4] Add docs to gitignore. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d136d45..730a50e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ dist test-types.js ldclient-user-cache /local/ +docs/ From 7c061eeed024ed0fe94a40b5be8e9c2137f73513 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:49:55 -0700 Subject: [PATCH 3/4] Add contract test service to CI. --- .github/workflows/ci.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6c5d82..0836858 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,8 @@ jobs: ] runs-on: ${{ matrix.variations.os }} + env: + TEST_SERVICE_PORT: 8000 steps: - uses: actions/checkout@v4 @@ -35,5 +37,11 @@ jobs: run: npm run lint:all - name: Check typescript run: npm run check-typescript + - name: Run contract test service + run: npm run contract-test-service 2>&1 & + - uses: launchdarkly/gh-actions/actions/contract-tests@contract-tests-v1.0.0 + with: + test_service_port: ${{ env.TEST_SERVICE_PORT }} + token: ${{ secrets.GITHUB_TOKEN }} - name: Build Docs run: npm run doc From e1658fe9a0ab3fcd1ec36012560facdf372e3cb6 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Fri, 18 Oct 2024 09:51:16 -0700 Subject: [PATCH 4/4] feat: Add support for client-side prerequisite events. --- contract-tests/index.js | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/contract-tests/index.js b/contract-tests/index.js index 0ff6e4e..2b7124c 100644 --- a/contract-tests/index.js +++ b/contract-tests/index.js @@ -26,6 +26,7 @@ app.get('/', (req, res) => { 'user-type', 'inline-context', 'anonymous-redaction', + 'client-prereq-events', ], }); }); diff --git a/package.json b/package.json index 41aeb96..748429f 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ }, "dependencies": { "launchdarkly-eventsource": "2.0.3", - "launchdarkly-js-sdk-common": "5.2.0", + "launchdarkly-js-sdk-common": "5.4.0", "node-localstorage": "^1.3.1" }, "repository": {