Skip to content

About

Open Collective's PDF Server

Topics

Resources

Contributing

Security policy

Stars

87 stars

Watchers

19 watching

Forks

Repository files navigation

Open Collective PDF service

Foreword

If you see a step below that could be improved (or is outdated), please update the instructions. We rarely go through this process ourselves, so your fresh pair of eyes and your recent experience with it, makes you the best candidate to improve them for other users. Thank you!

Development

Prerequisite

Install

We recommend cloning the repository in a folder dedicated to opencollective projects.

git clone git@github.com:opencollective/opencollective-pdf.git opencollective/pdf
cd opencollective/pdf
npm install

Start

To start the service:

npm run dev

Usage with frontend

If you use this service through local frontend, you will need to add PDF_SERVICE_URL=http://localhost:3002 line to .env. You're ready to go - frontend will pass your authorization token directly to the app.

However this is not practical to develop, you should only use it to debug the bridge between the two services.

Calling URLs directly

This method can be usefull to debug staging or production invoices, or to work with you local development data. It is also the best way if you need to make changes to the graphql queries.

The easier to make it work is to go to /:userSlug/admin/for-developers on the frontend, generate a personal token, and to add ?personalToken=your_key_here to all your requests.

Invoice template images

Invoice template images (embeddedImage) are only downloaded from public addresses. In development (NODE_ENV=development), private addresses such as localhost are allowed so that MinIO and the local images service work. Set ALLOW_PRIVATE_IMAGE_URLS=true to allow them in other environments, or ALLOW_PRIVATE_IMAGE_URLS=false to block them in development.

Contributing

Code style? Commit convention? Please check our Contributing guidelines.

TL;DR: we use Prettier and ESLint, we do like great commit messages and clean Git history.

Tests

  • Run all tests: npm test
  • Run tests in watch mode: npm run test:watch
  • Run tests with coverage report: npm run test:coverage

Be aware that watch currently doesn't auto-reload the express app.

Deployment

Merging to main branch will auto-deploy the pdf service to Heroku.

Monitoring (Sentry)

Errors (including uncaught exceptions and unhandled rejections), traces, and profiles are reported to Sentry with @sentry/node when SENTRY_DSN is set. Sampling is off by default. The SDK is initialized in instrument.ts, loaded before the app via node --import (see https://docs.sentry.io/platforms/javascript/guides/express/).

Variable Default Description
SENTRY_DSN (unset = disabled) Sentry project DSN for opencollective-pdf
SENTRY_ENVIRONMENT OC_ENV / NODE_ENV Sentry environment
SENTRY_TRACES_SAMPLE_RATE 0 Tracing sample rate (0–1)
SENTRY_PROFILES_SAMPLE_RATE 0 Profiling sample rate (0–1, profiler loads when >0)

Set these as Heroku config vars on staging/production. Expected client errors (3xx/4xx, including PDFServiceError with a status below 500) are not reported; 5xx and status-less errors are. Authorization / API-key headers, cookies, and token query params are redacted before sending (see server/lib/sentry.ts).

Verifying Sentry end-to-end

GET /debug-sentry?key=<DEBUG_SENTRY_KEY> throws a test error that Sentry captures. It behaves like an unknown route (404) unless DEBUG_SENTRY_KEY is configured and the key query parameter matches it. Set DEBUG_SENTRY_KEY only where you need to verify (e.g. staging), never as a long-lived production secret.

About

Open Collective's PDF Server

Topics

Resources

Contributing

Security policy

Stars

87 stars

Watchers

19 watching

Forks

Sponsor this project

Used by

Contributors

Languages