Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

10 changes: 0 additions & 10 deletions .eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/build-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- id: setup-node
uses: actions/setup-node@v2.5.1
with:
node-version: 12
node-version: 18
registry-url: https://registry.npmjs.org/
- id: build-and-analyse
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- id: setup-node
uses: actions/setup-node@v2.5.1
with:
node-version: 12
node-version: 18
registry-url: https://registry.npmjs.org/
- id: build-and-analyse
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- id: setup-node
uses: actions/setup-node@v2.5.1
with:
node-version: 12
node-version: 18
registry-url: https://registry.npmjs.org/
- id: build-and-analyse
env:
Expand Down
30 changes: 28 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
./nyc_output
documentation
nyc_output
coverage
examples
src
test
types
.DS_Store
website
documentation
documentation
# System and IDE files
Thumbs.db
.vscode/
.idea/

# Logs and environment
*.log
*.env
npm-debug.log

# Node and package manager
node_modules/
package-lock.json
yarn.lock

# Config files
.eslintrc*
.prettierrc*
.babelrc*
.editorconfig

# Source maps and TypeScript (if not needed)
*.ts
*.map
7 changes: 0 additions & 7 deletions .prettierrc

This file was deleted.

31 changes: 31 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import prettier from "eslint-config-prettier";

export default [
{
ignores: [
"coverage/",
"dist/",
"examples/",
"test/",
"node_modules/",
"types/"
],
},
{
files: ["src/**/*.js"],
languageOptions: {
ecmaVersion: 2022,
sourceType: "module",
globals: {
URL: "readonly",
URLSearchParams: "readonly",
Buffer: "readonly",
process: "readonly",
fetch: "readonly"
}
},
rules: {
}
},
prettier
];
23 changes: 0 additions & 23 deletions example.js

This file was deleted.

34 changes: 15 additions & 19 deletions examples/simple_issue_408_fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@
* Handles malformed authentication_failed webhooks with HTTP clients
*/

const { parseWebhookPayload, extractAuthenticationFailedData } = require('../src/services/webhook-utils.js');
const { sanitizeForLog, sanitizePaymentId, sanitizeError, sanitizeAgainstLogInjection } = require('./utils/security.js');

// Try to load node-fetch for Node 12 compatibility
let fetch;
try {
fetch = require('node-fetch');
} catch (error) {
// node-fetch not available, will use simulation
console.log(`📝 Note: Install with: npm install node-fetch@2, ${error.message}`);
import { parseWebhookPayload, extractAuthenticationFailedData } from '../src/services/webhook-utils.js';
import { sanitizeForLog, sanitizePaymentId, sanitizeError, sanitizeAgainstLogInjection } from './utils/security.js';
import http from 'http';

// Use native fetch in Node 18+ only
const fetch = typeof globalThis.fetch === 'function' ? globalThis.fetch : undefined;
if (!fetch) {
console.log('📝 Note: Native fetch is only available in Node 18+. Please upgrade your Node.js version.');
}

// Try to load axios
let axios;
try {
axios = require('axios');
axios = (await import('axios')).default;
} catch (error) {
// axios not available, will use simulation
console.log(`📝 Note: Install with: npm install axios, ${error.message}`);
Expand Down Expand Up @@ -70,23 +68,23 @@ try {

// === HTTP CLIENT EXAMPLES ===

// Example 1: Using with node-fetch (compatible with Node 12+)
// Example 1: Using with native fetch (compatible with Node 18+)
async function handleWebhookWithFetch(rawPayload) {
console.log('\n🌐 Example: Using with node-fetch');
console.log('\n🌐 Example: Using with native fetch');

try {
if (!fetch) {
console.log('📝 Note: Install with: npm install node-fetch@2');
console.log('📝 Note: Native fetch is only available in Node 18+. Please upgrade your Node.js version.');
} else {
console.log('📝 node-fetch available for HTTP requests');
console.log('📝 Native fetch available for HTTP requests');
}

// Process webhook payload (main functionality)
const webhook = parseWebhookPayload(rawPayload);
const data = extractAuthenticationFailedData(webhook);

console.log('✅ Processed payment:', sanitizePaymentId(data.paymentId));
console.log(` Status: ${fetch ? 'node-fetch available' : 'simulation mode'}`);
console.log(` Status: ${fetch ? 'native fetch available' : 'simulation mode'}`);

return data;
} catch (error) {
Expand Down Expand Up @@ -122,8 +120,6 @@ async function handleWebhookWithAxios(rawPayload) {
function createNodeHttpWebhookServer() {
console.log('\n🌐 Example: Node.js HTTP server');

const http = require('http');

const server = http.createServer((req, res) => {
if (req.method === 'POST' && req.url === '/webhooks/auth-failed') {
let rawPayload = '';
Expand Down Expand Up @@ -243,7 +239,7 @@ console.log('2. Works with node-fetch, axios, or native http');
console.log('3. Handles Unicode issues automatically');
console.log('4. sanitizeAgainstLogInjection() prevents advanced log attacks');

module.exports = {
export {
webhookHandler,
handleWebhookWithFetch,
handleWebhookWithAxios,
Expand Down
2 changes: 1 addition & 1 deletion examples/utils/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ const sanitizeAgainstLogInjection = (input) => sanitize(input, {
redactSensitive: true
});

module.exports = {
export {
sanitize,
sanitizeForLog,
sanitizePaymentId,
Expand Down
5 changes: 5 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"checkJs": false
}
}
Loading