diff --git a/apxtri/apxtri.js b/apxtri/apxtri.js index 6c09faa..5706a4a 100755 --- a/apxtri/apxtri.js +++ b/apxtri/apxtri.js @@ -1,16 +1,27 @@ -// CRITICAL FIX: Ensure Buffer is available globally before ANY modules load +// CRITICAL FIX: Ensure Buffer and SlowBuffer are available globally before ANY modules load // This fixes the "Cannot read properties of undefined (reading 'prototype')" error -if (typeof global !== 'undefined') { - // Force load buffer module and make it globally available +// SlowBuffer was deprecated in Node 18+ and removed in Node 22+, but some packages still use it +(function() { + const Module = require('module'); + const originalRequire = Module.prototype.require; + + // Patch require to ensure buffer module always has SlowBuffer + Module.prototype.require = function(id) { + if (id === 'buffer') { + const buf = originalRequire.apply(this, arguments); + if (!buf.SlowBuffer) buf.SlowBuffer = buf.Buffer; + return buf; + } + return originalRequire.apply(this, arguments); + }; + + // Also ensure global Buffer/SlowBuffer are available const buffer = require('buffer'); - if (!global.Buffer) { - global.Buffer = buffer.Buffer; - } - // Also ensure it's available in this scope - if (typeof Buffer === 'undefined') { - global.Buffer = buffer.Buffer; - } -} + if (!global.Buffer) global.Buffer = buffer.Buffer; + if (!global.SlowBuffer) global.SlowBuffer = buffer.Buffer; + if (globalThis && !globalThis.Buffer) globalThis.Buffer = buffer.Buffer; + if (globalThis && !globalThis.SlowBuffer) globalThis.SlowBuffer = buffer.Buffer; +})(); // Double-check Buffer is available if (typeof Buffer === 'undefined') { diff --git a/apxtri/models/Pagans.js b/apxtri/models/Pagans.js index 08be6de..9246102 100644 --- a/apxtri/models/Pagans.js +++ b/apxtri/models/Pagans.js @@ -10,7 +10,9 @@ const Odmdb = require("./Odmdb.js"); const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`); const currentmod = "Pagans"; -const log = process.env.ACTIVELOG ? process.env.ACTIVELOG.split(',').includes(currentmod) : false; +const log = process.env.ACTIVELOG + ? process.env.ACTIVELOG.split(",").includes(currentmod) + : false; /** * Pagan Management numeric Identity and Person (Person = Pagan Id + tribe) * @@ -56,22 +58,22 @@ Pagans.keyrecovery = (emailalias, tribe, search, lg) => { emailalias, tribe, search, - lg + lg, ); - if (!search || search.length<3) { + if (!search || search.length < 3) { console.log( currentmod, "issue with search : emailalias, tribe, search, lg:", emailalias, tribe, search, - lg + lg, ); return { status: 406, ref: "Pagans", msg: "nosearchstring", - data: {emailalias,tribe,search,lg}, + data: { emailalias, tribe, search, lg }, }; } if (!["email", "alias"].includes(emailalias)) { @@ -79,7 +81,7 @@ Pagans.keyrecovery = (emailalias, tribe, search, lg) => { status: 406, ref: "Pagans", msg: "emailaliasnotemailoralias", - data: {emailalias,tribe,search,lg}, + data: { emailalias, tribe, search, lg }, }; } let emaillist = []; @@ -107,9 +109,9 @@ Pagans.keyrecovery = (emailalias, tribe, search, lg) => { const ret = Pagans.sendmailkey(e); });*/ for (let i = 0; i < emaillist.length && i < 3; i++) { - const e = emaillist[i]; - const ret = Pagans.sendmailkey(e); -} + const e = emaillist[i]; + const ret = Pagans.sendmailkey(e); + } if (emaillist.length > 0) { return { status: 200, @@ -143,14 +145,16 @@ Pagans.getalias = (alias) => { data: fs.readJSONSync(`../adminapi/objects/pagans/itm/${alias}.json`), }; } else { - try{ - const lst_alias=fs.readJSONSync(`../adminapi/objects/pagans/idx/lst_alias.json`) - let suggestedalias=[] + try { + const lst_alias = fs.readJSONSync( + `../adminapi/objects/pagans/idx/lst_alias.json`, + ); + let suggestedalias = []; let counter = 1; - while (suggestedalias.length < 3){ + while (suggestedalias.length < 3) { const candidate = `${alias}${counter}`; - if (!lst_alias.includes(candidate)){ - suggestedalias.push(candidate) + if (!lst_alias.includes(candidate)) { + suggestedalias.push(candidate); } counter++; } @@ -160,8 +164,9 @@ Pagans.getalias = (alias) => { msg: "aliasdoesnotexist", data: { alias, suggestedalias }, }; - } catch(err){ - return {status:500,msg:"lst_aliaserror",ref:"Pagans",data:{}} + } catch (err) { + return { status: 500, msg: "lst_aliaserror", ref: "Pagans", data: {} }; + } } }; @@ -195,7 +200,7 @@ Pagans.sendmailkey = (data) => { "-", data.email, "-", - data.lg + data.lg, ); const person = { alias: data.alias, @@ -253,7 +258,7 @@ Pagans.sendmailkey = (data) => { contentType:"text/plain" }, */ - + const maildata = { from: tplemail.sender, to: person.email, @@ -275,7 +280,7 @@ Pagans.authenticatedetachedSignature = async ( alias, pubK, detachedSignature, - message + message, ) => { /** * Check that a message was signed with a privateKey from a publicKey