Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix: harden npm package per modern best practices

Mario7145488bd3a3
diff --git a/npm/LICENSE b/npm/LICENSE
new file mode 100644
index 00000000..beb32a73
--- /dev/null
+++ b/npm/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2026 Luigi Agosti
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/npm/package.json b/npm/package.json
index 49ef448b..f1a83a50 100644
--- a/npm/package.json
+++ b/npm/package.json
@@ -7,6 +7,9 @@
"bin": {
"pinchtab": "bin/pinchtab"
},
+ "repository": "github:pinchtab/pinchtab",
+ "homepage": "https://github.com/pinchtab/pinchtab#readme",
+ "bugs": "https://github.com/pinchtab/pinchtab/issues",
"scripts": {
"build": "tsc",
"test": "node --test dist/tests/integration.test.js",
@@ -16,14 +19,19 @@
"files": [
"dist",
"bin",
- "scripts"
+ "scripts",
+ "LICENSE"
],
"keywords": [
"browser",
"automation",
"api",
"agent",
- "ai"
+ "ai",
+ "headless",
+ "chromedp",
+ "stealth",
+ "ai-agent"
],
"author": "Mario <[email protected]>",
"license": "MIT",
diff --git a/npm/scripts/postinstall.js b/npm/scripts/postinstall.js
index 4852e321..e21c9822 100644
--- a/npm/scripts/postinstall.js
+++ b/npm/scripts/postinstall.js
@@ -4,9 +4,15 @@ const https = require('https');
const fs = require('fs');
const path = require('path');
const os = require('os');
+const crypto = require('crypto');
const GITHUB_REPO = 'pinchtab/pinchtab';
-const VERSION = '0.7.0';
+
+function getVersion() {
+ const pkgPath = path.join(__dirname, '..', 'package.json');
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
+ return pkg.version;
+}
function detectPlatform() {
const platform = process.platform;
@@ -40,7 +46,65 @@ function getBinDir() {
return path.join(os.homedir(), '.pinchtab', 'bin');
}
-async function downloadBinary(platform) {
+function fetchUrl(url) {
+ return new Promise((resolve, reject) => {
+ https.get(url, (response) => {
+ if (response.statusCode === 404) {
+ reject(new Error(`Not found: ${url}`));
+ return;
+ }
+
+ if (response.statusCode !== 200) {
+ reject(new Error(`HTTP ${response.statusCode}: ${url}`));
+ return;
+ }
+
+ const chunks = [];
+ response.on('data', (chunk) => chunks.push(chunk));
+ response.on('end', () => resolve(Buffer.concat(chunks)));
+ response.on('error', reject);
+ }).on('error', reject);
+ });
+}
+
+async function downloadChecksums(version) {
+ const url = `https://github.com/${GITHUB_REPO}/releases/download/v${version}/checksums.txt`;
+
+ try {
+ const data = await fetchUrl(url);
+ const checksums = new Map();
+
+ data
+ .toString('utf-8')
+ .trim()
+ .split('\n')
+ .forEach((line) => {
+ const parts = line.split(/\s+/);
+ if (parts.length >= 2) {
+ const hash = parts[0];
+ const filename = parts[1];
+ checksums.set(filename.trim(), hash.trim());
+ }
+ });
+
+ return checksums;
+ } catch (err) {
+ throw new Error(
+ `Failed to download checksums: ${err.message}\n` +
+ `Ensure v${version} is released on GitHub with checksums.txt`
+ );
+ }
+}
+
+function verifySHA256(filePath, expectedHash) {
+ const hash = crypto.createHash('sha256');
+ const data = fs.readFileSync(filePath);
+ hash.update(data);
+ const actualHash = hash.digest('hex');
+ return actualHash.toLowerCase() === expectedHash.toLowerCase();
+}
+
+async function downloadBinary(platform, version) {
const binaryName = getBinaryName(platform);
const binDir = getBinDir();
const binaryPath = path.join(binDir, binaryName);
@@ -51,62 +115,84 @@ async function downloadBinary(platform) {
return;
}
- const downloadUrl = `https://github.com/${GITHUB_REPO}/releases/download/v${VERSION}/${binaryName}`;
+ // Fetch checksums
+ console.log(`Downloading Pinchtab ${version} for ${platform.os}-${platform.arch}...`);
+ const checksums = await downloadChecksums(version);
+
+ if (!checksums.has(binaryName)) {
+ throw new Error(
+ `Binary not found in checksums: ${binaryName}\n` +
+ `Available: ${Array.from(checksums.keys()).join(', ')}`
+ );
+ }
- console.log(`Downloading Pinchtab ${VERSION} for ${platform.os}-${platform.arch}...`);
+ const expectedHash = checksums.get(binaryName);
+ const downloadUrl = `https://github.com/${GITHUB_REPO}/releases/download/v${version}/${binaryName}`;
// Ensure directory exists
if (!fs.existsSync(binDir)) {
fs.mkdirSync(binDir, { recursive: true });
}
+ // Download binary
return new Promise((resolve, reject) => {
- https
- .get(downloadUrl, (response) => {
- if (response.statusCode === 404) {
- console.warn(
- `⚠ Binary not found at ${downloadUrl}. Make sure v${VERSION} is released on GitHub.`
- );
- resolve();
- return;
- }
+ console.log(`Downloading from ${downloadUrl}...`);
- if (response.statusCode !== 200) {
- console.warn(`⚠ Download failed with status ${response.statusCode}`);
- resolve();
- return;
- }
+ const file = fs.createWriteStream(binaryPath);
- const file = fs.createWriteStream(binaryPath);
- response.pipe(file);
+ https.get(downloadUrl, (response) => {
+ if (response.statusCode !== 200) {
+ fs.unlink(binaryPath, () => {});
+ reject(new Error(`HTTP ${response.statusCode}: ${downloadUrl}`));
+ return;
+ }
- file.on('finish', () => {
- file.close();
- fs.chmodSync(binaryPath, 0o755);
- console.log(`✓ Downloaded to ${binaryPath}`);
- resolve();
- });
+ response.pipe(file);
- file.on('error', (err) => {
+ file.on('finish', () => {
+ file.close();
+
+ // Verify checksum
+ if (!verifySHA256(binaryPath, expectedHash)) {
fs.unlink(binaryPath, () => {});
- reject(err);
- });
- })
- .on('error', (err) => {
- console.warn(`⚠ Failed to download: ${err.message}`);
+ reject(
+ new Error(
+ `Checksum verification failed for ${binaryName}\n` +
+ `Downloaded file may be corrupted. Please try installing again.`
+ )
+ );
+ return;
+ }
+
+ // Make executable
+ fs.chmodSync(binaryPath, 0o755);
+ console.log(`✓ Verified and installed: ${binaryPath}`);
resolve();
});
+
+ file.on('error', (err) => {
+ fs.unlink(binaryPath, () => {});
+ reject(err);
+ });
+ }).on('error', reject);
});
}
-// Run download
-const platform = detectPlatform();
-downloadBinary(platform)
- .then(() => {
+// Main
+(async () => {
+ try {
+ const platform = detectPlatform();
+ const version = getVersion();
+ await downloadBinary(platform, version);
console.log('✓ Pinchtab setup complete');
process.exit(0);
- })
- .catch((err) => {
- console.error('✗ Setup error:', err.message);
+ } catch (err) {
+ console.error('\n✗ Failed to setup Pinchtab:');
+ console.error(` ${(err instanceof Error ? err.message : String(err)).split('\n').join('\n ')}`);
+ console.error('\nTroubleshooting:');
+ console.error(' • Check your internet connection');
+ console.error(' • Verify the release exists: https://github.com/pinchtab/pinchtab/releases');
+ console.error(' • Try again: npm rebuild pinchtab');
process.exit(1);
- });
+ }
+})();
diff --git a/npm/src/download.ts b/npm/src/download.ts
index ab761bbb..b74b5fbd 100644
--- a/npm/src/download.ts
+++ b/npm/src/download.ts
@@ -1,9 +1,16 @@
import * as fs from 'fs';
import * as path from 'path';
import * as https from 'https';
+import * as crypto from 'crypto';
const GITHUB_REPO = 'pinchtab/pinchtab';
-const VERSION = '0.7.0';
+
+// Read version from package.json at build time
+function getVersion(): string {
+ const pkgPath = path.join(__dirname, '..', 'package.json');
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
+ return pkg.version;
+}
interface Platform {
os: 'darwin' | 'linux' | 'windows';
@@ -31,7 +38,7 @@ function detectPlatform(): Platform {
function getBinaryName(platform: Platform): string {
const { os, arch } = platform;
const archName = arch === 'arm64' ? 'arm64' : 'x64';
-
+
if (os === 'windows') {
return `pinchtab-${os}-${archName}.exe`;
}
@@ -42,7 +49,63 @@ function getBinDir(): string {
return path.join(process.env.HOME || process.env.USERPROFILE || '', '.pinchtab', 'bin');
}
-async function downloadBinary(platform: Platform): Promise<void> {
+function fetchUrl(url: string): Promise<Buffer> {
+ return new Promise((resolve, reject) => {
+ https.get(url, (response) => {
+ if (response.statusCode === 404) {
+ reject(new Error(`Not found: ${url}`));
+ return;
+ }
+
+ if (response.statusCode !== 200) {
+ reject(new Error(`HTTP ${response.statusCode}: ${url}`));
+ return;
+ }
+
+ const chunks: Buffer[] = [];
+ response.on('data', (chunk) => chunks.push(chunk));
+ response.on('end', () => resolve(Buffer.concat(chunks)));
+ response.on('error', reject);
+ }).on('error', reject);
+ });
+}
+
+async function downloadChecksums(version: string): Promise<Map<string, string>> {
+ const url = `https://github.com/${GITHUB_REPO}/releases/download/v${version}/checksums.txt`;
+
+ try {
+ const data = await fetchUrl(url);
+ const checksums = new Map<string, string>();
+
+ data
+ .toString('utf-8')
+ .trim()
+ .split('\n')
+ .forEach((line) => {
+ const [hash, filename] = line.split(/\s+/);
+ if (hash && filename) {
+ checksums.set(filename.trim(), hash.trim());
+ }
+ });
+
+ return checksums;
+ } catch (err) {
+ throw new Error(
+ `Failed to download checksums: ${(err as Error).message}. ` +
+ `Ensure v${version} is released on GitHub with checksums.txt`
+ );
+ }
+}
+
+function verifySHA256(filePath: string, expectedHash: string): boolean {
+ const hash = crypto.createHash('sha256');
+ const data = fs.readFileSync(filePath);
+ hash.update(data);
+ const actualHash = hash.digest('hex');
+ return actualHash.toLowerCase() === expectedHash.toLowerCase();
+}
+
+async function downloadBinary(platform: Platform, version: string): Promise<void> {
const binaryName = getBinaryName(platform);
const binDir = getBinDir();
const binaryPath = path.join(binDir, binaryName);
@@ -53,58 +116,75 @@ async function downloadBinary(platform: Platform): Promise<void> {
return;
}
- const downloadUrl = `https://github.com/${GITHUB_REPO}/releases/download/v${VERSION}/${binaryName}`;
+ // Fetch checksums
+ console.log(`Downloading Pinchtab ${version} for ${platform.os}-${platform.arch}...`);
+ const checksums = await downloadChecksums(version);
- console.log(`Downloading Pinchtab ${VERSION} for ${platform.os}-${platform.arch}...`);
- console.log(`URL: ${downloadUrl}`);
+ if (!checksums.has(binaryName)) {
+ throw new Error(
+ `Binary not found in checksums: ${binaryName}. ` +
+ `Available: ${Array.from(checksums.keys()).join(', ')}`
+ );
+ }
+
+ const expectedHash = checksums.get(binaryName)!;
+ const downloadUrl = `https://github.com/${GITHUB_REPO}/releases/download/v${version}/${binaryName}`;
// Ensure directory exists
if (!fs.existsSync(binDir)) {
fs.mkdirSync(binDir, { recursive: true });
}
+ // Download binary
return new Promise((resolve, reject) => {
- https
- .get(downloadUrl, (response) => {
- if (response.statusCode === 404) {
+ console.log(`Downloading from ${downloadUrl}...`);
+
+ const file = fs.createWriteStream(binaryPath);
+
+ https.get(downloadUrl, (response) => {
+ if (response.statusCode !== 200) {
+ fs.unlink(binaryPath, () => {});
+ reject(new Error(`HTTP ${response.statusCode}: ${downloadUrl}`));
+ return;
+ }
+
+ response.pipe(file);
+
+ file.on('finish', () => {
+ file.close();
+
+ // Verify checksum
+ if (!verifySHA256(binaryPath, expectedHash)) {
+ fs.unlink(binaryPath, () => {});
reject(
new Error(
- `Binary not found: ${downloadUrl}. Make sure v${VERSION} is released on GitHub.`
+ `Checksum verification failed for ${binaryName}. ` +
+ `Download may be corrupted. Please try again.`
)
);
return;
}
- if (response.statusCode !== 200) {
- reject(new Error(`Download failed with status ${response.statusCode}`));
- return;
- }
-
- const file = fs.createWriteStream(binaryPath);
- response.pipe(file);
-
- file.on('finish', () => {
- file.close();
- // Make executable
- fs.chmodSync(binaryPath, 0o755);
- console.log(`✓ Downloaded to ${binaryPath}`);
- resolve();
- });
+ // Make executable
+ fs.chmodSync(binaryPath, 0o755);
+ console.log(`✓ Verified and installed: ${binaryPath}`);
+ resolve();
+ });
- file.on('error', (err) => {
- fs.unlink(binaryPath, () => {});
- reject(err);
- });
- })
- .on('error', (err) => {
+ file.on('error', (err) => {
+ fs.unlink(binaryPath, () => {});
reject(err);
});
+ }).on('error', reject);
});
}
export async function ensureBinary(): Promise<string> {
const platform = detectPlatform();
- await downloadBinary(platform);
+ const version = getVersion();
+
+ await downloadBinary(platform, version);
+
const binDir = getBinDir();
const binaryName = getBinaryName(platform);
return path.join(binDir, binaryName);