> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kodostatus.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Upload Source Map

> Upload source maps for readable stack traces in error reports

<Info>
  Source map uploads are available on Pro and Team plans.
</Info>

Source maps allow Kodo to translate minified JavaScript stack traces into readable source code with original file names, line numbers, and column positions.

## Request

This endpoint accepts `multipart/form-data` for file uploads.

<ParamField body="file" type="file" required>
  The source map file (.map)
</ParamField>

<ParamField body="url" type="string" required>
  The URL of the minified JavaScript file this map corresponds to (e.g., "[https://example.com/assets/app.min.js](https://example.com/assets/app.min.js)")
</ParamField>

<ParamField body="release" type="string" required>
  Release version this source map belongs to
</ParamField>

<ParamField body="service_id" type="string" required>
  Service ID
</ParamField>

## Response

Returns upload confirmation.

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://kodostatus.com/api/v1/sourcemaps" \
    -H "X-API-Key: your_api_key" \
    -F "file=@dist/app.min.js.map" \
    -F "url=https://example.com/assets/app.min.js" \
    -F "release=1.2.3" \
    -F "service_id=svc_abc123"
  ```

  ```javascript Node.js theme={null}
  const FormData = require('form-data');
  const fs = require('fs');

  const form = new FormData();
  form.append('file', fs.createReadStream('dist/app.min.js.map'));
  form.append('url', 'https://example.com/assets/app.min.js');
  form.append('release', '1.2.3');
  form.append('service_id', 'svc_abc123');

  const response = await fetch('https://kodostatus.com/api/v1/sourcemaps', {
    method: 'POST',
    headers: {
      'X-API-Key': process.env.KODO_API_KEY,
      ...form.getHeaders()
    },
    body: form
  });
  ```

  ```yaml GitHub Actions theme={null}
  - name: Upload Source Maps to Kodo
    run: |
      for map in dist/*.map; do
        js_file="${map%.map}"
        curl -X POST "https://kodostatus.com/api/v1/sourcemaps" \
          -H "X-API-Key: ${{ secrets.KODO_API_KEY }}" \
          -F "file=@$map" \
          -F "url=https://example.com/assets/$(basename $js_file)" \
          -F "release=${{ github.ref_name }}" \
          -F "service_id=svc_abc123"
      done
  ```
</RequestExample>

<ResponseExample>
  ```json theme={null}
  {
    "success": true,
    "sourcemap": {
      "id": "sm_abc123",
      "url": "https://example.com/assets/app.min.js",
      "release": "1.2.3",
      "size_bytes": 245678,
      "uploaded_at": "2024-01-15T10:00:00Z"
    }
  }
  ```
</ResponseExample>

## Build Tool Integration

### Webpack

```javascript webpack.config.js theme={null}
const KodoSourceMapPlugin = require('@kodo/webpack-plugin');

module.exports = {
  devtool: 'source-map',
  plugins: [
    new KodoSourceMapPlugin({
      apiKey: process.env.KODO_API_KEY,
      serviceId: 'svc_abc123',
      release: process.env.VERSION
    })
  ]
};
```

### Vite

```javascript vite.config.js theme={null}
import { kodoSourcemaps } from '@kodo/vite-plugin';

export default {
  build: { sourcemap: true },
  plugins: [
    kodoSourcemaps({
      apiKey: process.env.KODO_API_KEY,
      serviceId: 'svc_abc123',
      release: process.env.VERSION
    })
  ]
};
```

<Warning>
  Source maps should not be served publicly as they expose your original source code. Upload them to Kodo and remove them from your production deployment.
</Warning>
