name: Publish Node.js SDK to npm

on:
  release:
    types: [published]
  workflow_dispatch:  # Allow manual trigger

defaults:
  run:
    working-directory: sdk/nodejs

jobs:
  publish:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      id-token: write  # Required for npm OIDC trusted publishing
    steps:
      - uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '24'  # Node 24+ includes npm 11.5.1+ required for OIDC
          registry-url: 'https://registry.npmjs.org'

      - name: Install dependencies
        run: npm ci

      - name: Build
        run: npm run build

      - name: Publish to npm with OIDC trusted publishing
        run: npm publish --access public --provenance
        # No NODE_AUTH_TOKEN needed - uses OIDC trusted publishing
        # Configure trusted publisher at: https://www.npmjs.com/package/@autodoc-ai/sdk/access
