Skip to content

Commit

Permalink
Switch to CommonJS for maximum compatibility
Browse files Browse the repository at this point in the history
Importing via ESM continues to work the same, so this is not a
backwards-incompatible change.
  • Loading branch information
jstayton committed Nov 5, 2024
1 parent f5319b7 commit ca9035e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ imported to begin:
import verifyTruepicWebhook from '@truepic/webhook-verifier'
```

CommonJS is also supported:

```js
const verifyTruepicWebhook = require('@truepic/webhook-verifier')
```

This `verifyTruepicWebhook` function (or whatever you imported it as) is then
called with the following arguments:

Expand Down
11 changes: 6 additions & 5 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import js from '@eslint/js'
import prettier from 'eslint-config-prettier'
import node from 'eslint-plugin-n'
import globals from 'globals'
const js = require('@eslint/js')
const prettier = require('eslint-config-prettier')
const node = require('eslint-plugin-n')
const globals = require('globals')

export default [
module.exports = [
{
languageOptions: {
globals: { ...globals.node },
sourceType: 'commonjs',
},
},
{
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "@truepic/webhook-verifier",
"version": "1.4.0",
"type": "module",
"description": "Verify webhooks from Truepic Vision or Lens in your Node.js app",
"homepage": "https://github.com/TRUEPIC/webhook-verifier-nodejs#readme",
"bugs": "https://github.com/TRUEPIC/webhook-verifier-nodejs/issues",
Expand Down
2 changes: 1 addition & 1 deletion src/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ class TruepicWebhookVerifierError extends Error {
}
}

export default TruepicWebhookVerifierError
module.exports = TruepicWebhookVerifierError
8 changes: 4 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createHmac, timingSafeEqual } from 'node:crypto'
import TruepicWebhookVerifierError from './error.js'
const { createHmac, timingSafeEqual } = require('node:crypto')
const TruepicWebhookVerifierError = require('./error')

/**
* Parse the `truepic-signature` header into timestamp and signature values.
Expand Down Expand Up @@ -164,5 +164,5 @@ function verifyTruepicWebhook({
}

/** @module @truepic/webhook-verifier */
export default verifyTruepicWebhook
export { TruepicWebhookVerifierError }
module.exports = verifyTruepicWebhook
module.exports.TruepicWebhookVerifierError = TruepicWebhookVerifierError
8 changes: 5 additions & 3 deletions src/main.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import verifyTruepicWebhook, { TruepicWebhookVerifierError } from './main.js'
const assert = require('node:assert/strict')
const { describe, it } = require('node:test')
const verifyTruepicWebhook = require('./main')

const { TruepicWebhookVerifierError } = verifyTruepicWebhook

describe('verifyTruepicWebhook', () => {
// Successful values.
Expand Down

0 comments on commit ca9035e

Please sign in to comment.