Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node): new unified code snippet for both the webhook and metrics (…
…#879) Redo the node code snippet for the webhook/metrics! We now have one code snippet that handles both cases super easily. ```javascript import { ReadMe } from 'readmeio' const readme = ReadMe('API_KEY') router.use( readme(async (req, getUser) => { // We pass in getUser which will call the correct function to fetch a // user depending on what we have in the request const user = getUser({ byEmail: getUserByEmail, // Function defined by them that returns a user given an email address byAPIKey: getUserByAPIKey, // Function defined by them that returns a user given an API key manualAPIKey: getAPIKey(req.headers.authorization), // Optional way to explicitly tell us the api key if we can't guess it }); return { name: user.name, email: user.email, keys: user.apiKeys, }; }, { development: process.env.NODE_ENV === 'development', // require development: true to show local testing page }) ); ``` Other things: * Added a /readme-setup page that walks users through making sure everything is configured properly. This page is only enabled if `development: true` to make sure that it won't be enabled in prod on accident. * Handles all of the metrics config in additional options parameter (which is optional) * Exported everything that was already there, so this is purely additive * User provided function should return all of the information about the user, even if it's not relevant for the specific API call that is happening. This means we can have one set of config for the webhook and metrics and the sdk will just figure out what is relevant for the call to metrics. * Makes a call to the ReadMe API to get the JWT Secret & stable version (for linking to the dash) ### Update 1/31 * I renamed some of the exports to clean it up a bit. Now we just have a `ReadMe` export that you call to pass in the API Key. Before we had a separate `auth` export that was required to be called before the middelware, which was confusing. This also cleans up how you call it (no more readmeio.readme stuff). This matches Sentry's sdks closer which makes me feel better about it. ## Testing * Install `readmeio@next` to test the new snippet * Docs on setup here: https://docs.readme.com/main/docs/unified-snippet-docs * PR for readme's api here: readmeio/readme#10819 Things to look out for: * Do the docs make sense? * Issues with copy in the local setup page? * Testing various APIs (with various auth types) --------- Co-authored-by: Tony Li <[email protected]> Co-authored-by: Kanad Gupta <[email protected]> Co-authored-by: Kanad Gupta <[email protected]> Co-authored-by: Jon Ursenbach <[email protected]> Co-authored-by: Bill Mill <[email protected]> Co-authored-by: Aaron Hedges <[email protected]> Co-authored-by: James Clark <[email protected]> Co-authored-by: James Clark <[email protected]>
- Loading branch information