#!/usr/bin/env bash set -e echo "=== Cleaning node_modules ===" rm -rf node_modules echo "OK" echo "=== Installing dependencies (ignoring scripts) ===" npm install --ignore-scripts echo "OK" echo "=== Locating Injected Store.js ===" TARGET=$(find node_modules/whatsapp-web.js/src/util/Injected -type f -name "Store.js" | head -n 1) if [ -z "$TARGET" ]; then echo "ERROR: Cannot find Store.js under Injected/" exit 1 fi echo "Found Injected file:" echo " $TARGET" echo "=== Backing up original ===" cp "$TARGET" "$TARGET.bak" echo "=== Applying getContactModel patch ===" # Patch de getContactModel functie sed -i '/getContactModel:/,/return {/c\ getContactModel: (contact) => {\n\ return {\n\ id: contact.id,\n\ name: contact.name,\n\ type: contact.type,\n\ \n\ isMe: contact.isMe || false,\n\ isUser: contact.isUser || false,\n\ isGroup: contact.isGroup || false,\n\ isBroadcast: contact.isBroadcast || false,\n\ isBusiness: contact.isBusiness || false,\n\ isEnterprise: contact.isEnterprise || false,\n\ \n\ isContactSyncEnabled: contact.isContactSyncEnabled || false,\n\ isContactLocked: contact.isContactLocked || false,\n\ \n\ verifiedLevel: contact.verifiedLevel,\n\ verifiedName: contact.verifiedName,\n\ pushname: contact.pushname,\n\ \n\ isWAContact: contact.isWAContact || false,\n\ \n\ isMyContact: (\n\ contact.isMyContact !== undefined\n\ ? contact.isMyContact\n\ : contact.type === \"in\" || false\n\ ),\n\ \n\ isBlocked: contact.isBlocked || false,\n\ \n\ labels: Array.isArray(contact.labels)\n\ ? contact.labels.map(l => l.id)\n\ : [],\n\ \n\ displayName: contact.displayName || contact.pushname || contact.name,\n\ formattedName: contact.formattedName || contact.name,\n\ formattedShortName: contact.formattedShortName || contact.name,\n\ shortName: contact.shortName || contact.name,\n\ isSaved: contact.isSaved !== undefined ? contact.isSaved : false,\n\ \n\ isMuted: contact.muteExpiration !== undefined\n\ ? contact.muteExpiration > 0\n\ : false,\n\ \n\ muteExpiration: contact.muteExpiration || 0,\n\ disappearingModeDuration: contact.disappearingModeDuration || 0,\n\ };\n\ },' "$TARGET" echo "=== Generating patch-package diff ===" npx patch-package whatsapp-web.js echo "OK" echo "=== Final npm install ===" npm install echo "SUCCESS — Patch applied, new diff created 🚀"