nylas / nylas-nodejs

A NodeJS wrapper for the Nylas REST API for email, contacts, and calendar.
MIT License
169 stars 118 forks source link

Add support for passing in headers to outgoing calls #552

Closed mrashed-dev closed 6 months ago

mrashed-dev commented 6 months ago

Description

This PR allows you to pass in a map of additional, custom headers that can be sent to the Node SDK.

Usage

This can be used one of two ways, for all outgoing calls or on a per-call-basis.

All Calls

For all outgoing calls, you can set headers when initializing the Nylas SDK:

const nylas = new Nylas({
  apiKey: "NYLAS_API_KEY",
  headers: {
    foo: "bar"
  },
});

messages = await nylas.messages.list({
  "identifier",
}); // Will be sent with 'foo: bar' header

calendars = await nylas.calendars.list({
  "identifier",
}); // Will be sent with 'foo: bar' header

Per-call basis

For all calls to the API, we have an override object. This object is now extended to include a headers field.

const nylas = new Nylas({
  apiKey: "NYLAS_API_KEY",
});

messages = await nylas.messages.list({
  "identifier",
  overrides: {
    headers: {
      foo: "bar"
    }
  }
}); // Will be sent with 'foo: bar' header

calendars = await nylas.calendars.list({
  "identifier",
}); // Will not be sent with 'foo: bar' header

License

I confirm that this contribution is made under the terms of the MIT license and that I have the authority necessary to make this contribution on behalf of its copyright owner.

mrashed-dev commented 6 months ago

@AaronDDM good callout, tests added.