Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
ci(sdk): publish the JavaScript SDK to npm via trusted publishing
Yudhi Armyndharis933a61187185
diff --git a/.github/workflows/js-sdk-release.yml b/.github/workflows/js-sdk-release.ymlnew file mode 100644index 000000000..7f205f122--- /dev/null+++ b/.github/workflows/js-sdk-release.yml@@ -0,0 +1,96 @@+name: JavaScript SDK Release++# Publishes @rmyndharis/openwa to npm from sdk/javascript.+#+# Authentication is npm Trusted Publishing (OIDC) — there is deliberately NO npm token anywhere in+# this workflow or in the repository secrets. npm mints a short-lived credential from the GitHub OIDC+# token, so nothing long-lived exists to leak or expire. It also removes this release path from the+# 2FA-bypass token deprecation entirely: those tokens lose direct publish in January 2027, whereas a+# trusted publisher is the migration target rather than a casualty of it.+#+# One-time setup on npmjs.com (see sdk/javascript/README.md -> Releasing), required BEFORE the first+# tag: package settings -> Trusted Publisher -> GitHub Actions, with organization `rmyndharis`,+# repository `OpenWA`, and workflow filename `js-sdk-release.yml`. Until that exists npm rejects the+# publish; the guard below fails first with a pointer rather than letting it surface as a raw 404.+#+# The SDK version is the package.json version on a dedicated tag (e.g. js-sdk-v0.2.0), NOT the+# monorepo v* app tags.++on:+ push:+ tags: ['js-sdk-v*']+ workflow_dispatch: {}++permissions:+ contents: read++jobs:+ publish:+ runs-on: ubuntu-latest+ defaults:+ run:+ working-directory: sdk/javascript+ permissions:+ contents: read+ # Mints the OIDC token npm exchanges for its short-lived publish credential. Without this the+ # publish falls back to looking for a token and fails — it is the whole mechanism.+ id-token: write+ steps:+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7++ # Guards are textual and secret-free, so a misconfigured release fails BEFORE anything is built+ # or published. Mirrors java-sdk-release.yml.+ - name: Guard — ref must be a js-sdk-v* release tag+ env:+ REF: ${{ github.ref }}+ run: |+ # workflow_dispatch can start this workflow on ANY ref; publishing an arbitrary branch or a+ # monorepo app tag to npm must not be possible.+ case "$REF" in+ refs/tags/js-sdk-v*) ;;+ *)+ echo "::error::This workflow publishes to npm and must run from a js-sdk-v* tag (got '$REF'). For workflow_dispatch, select the release tag as the run ref."+ exit 1+ ;;+ esac++ - name: Guard — tag version matches package.json version+ env:+ REF_NAME: ${{ github.ref_name }}+ run: |+ TAG_VERSION="${REF_NAME#js-sdk-v}"+ PKG_VERSION="$(node -p "require('./package.json').version")"+ if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then+ echo "::error::Tag '$REF_NAME' (version '$TAG_VERSION') does not match package.json version '$PKG_VERSION'. Bump the package or fix the tag before releasing."+ exit 1+ fi+ echo "Tag $REF_NAME matches package.json $PKG_VERSION"++ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7+ with:+ # Trusted publishing needs Node >= 22.14.0; '22' resolves to the latest 22.x, which is well+ # past that. No registry-url/NODE_AUTH_TOKEN: OIDC replaces the .npmrc token entirely.+ node-version: '22'+ cache: 'npm'+ cache-dependency-path: sdk/javascript/package-lock.json++ - name: Use an npm that supports trusted publishing+ # The npm bundled with Node 22 predates OIDC publishing (needs >= 11.5.1), and it fails by+ # looking for a token rather than by naming the missing support — so pin the requirement here.+ run: |+ npm install -g npm@latest+ npm --version++ - run: npm ci++ # Same gates as SDK CI, and for the same reason Java's release runs its tests: the artifact that+ # reaches the registry must be the one that passed, not a rebuild nobody checked.+ - run: npm test+ - run: npm run typecheck+ - run: npm run build+ - run: npm run smoke # dual CJS+ESM consumable — must run after build++ - name: Publish to npm (trusted publishing, provenance automatic)+ # No --provenance flag: npm attaches provenance on its own for a trusted-publisher release, and+ # passing it is redundant. --access public is explicit because the package is scoped.+ run: npm publish --access publicdiff --git a/CHANGELOG.md b/CHANGELOG.mdindex c0dc2f580..83b4ee512 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]+### Added++- **The JavaScript SDK now publishes to npm from CI** via Trusted Publishing (OIDC) on a `js-sdk-v*` tag — no npm token exists anywhere, and every release carries build provenance.+### Fixed- **A whatsapp-web.js session failing with `Execution context was destroyed` showed a bare Puppeteer error with no next step** — the advisory naming the likely stale browser profile went only to the server log, so the session card now carries a short form of it too.diff --git a/sdk/javascript/README.md b/sdk/javascript/README.mdindex 79c9b4d92..1e3cd5698 100644--- a/sdk/javascript/README.md+++ b/sdk/javascript/README.md@@ -46,6 +46,37 @@ each carrying `.status` and the parsed `.body`. Timeouts throw`OpenWATimeoutError`. The SDK does **not** retry — wrap calls with your ownbackoff if needed.+## Releasing++Publishing to npm is done by the+[`js-sdk-release.yml`](../../.github/workflows/js-sdk-release.yml) workflow,+which authenticates with **npm Trusted Publishing (OIDC)**. There is no npm+token in the workflow or in the repository secrets: npm mints a short-lived+credential from the GitHub OIDC token, and attaches build provenance+automatically. Nothing long-lived exists to leak, expire, or migrate when+2FA-bypass tokens lose direct publish in January 2027.++One-time setup, required **before** the first tag — on npmjs.com, open the+package settings for `@rmyndharis/openwa` and add a Trusted Publisher:++- Provider: **GitHub Actions**+- Organization: `rmyndharis`+- Repository: `OpenWA`+- Workflow filename: `js-sdk-release.yml` (the extension is part of the value)++There are no repository secrets to add. Until the trusted publisher exists npm+rejects the publish, so configure it first.++Cutting a release:++1. Bump `version` in `package.json` and land it on `main`.+2. Tag that commit `js-sdk-v<version>` (e.g. `js-sdk-v0.2.0`) and push the tag.+ The SDK has its own version line — the monorepo's `v*` tags are the app+ version and never trigger an SDK publish.+3. The workflow re-runs the SDK's tests, typecheck, build and dual CJS/ESM+ smoke check, then publishes. The published tarball is the one those gates+ passed, not a later rebuild.+## LicenseMIT