Edit: /tmp/tsx-0/17887-cc9f9b93361984b605b712c403457de113a71d91 (4616B)
{"code":"__filename=\"/opt/canhelp/node_modules/better-auth/dist/plugins/haveibeenpwned/index.mjs\";(()=>{\nvar __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __name=(target,value)=>__defProp(target,\"name\",{value,configurable:true});var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from===\"object\"||typeof from===\"function\"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},\"__esModule\",{value:true}),mod);var haveibeenpwned_exports={};__export(haveibeenpwned_exports,{haveIBeenPwned:()=>haveIBeenPwned});module.exports=__toCommonJS(haveibeenpwned_exports);var import_is_api_error=require(\"../../utils/is-api-error.mjs\");var import_api=require(\"../../api/index.mjs\");var import_context=require(\"@better-auth/core/context\");var import_error_codes=require(\"@better-auth/core/utils/error-codes\");var import_hash=require(\"@better-auth/utils/hash\");var import_fetch=require(\"@better-fetch/fetch\");const ERROR_CODES=(0,import_error_codes.defineErrorCodes)({PASSWORD_COMPROMISED:\"The password you entered has been compromised. Please choose a different password.\"});async function checkPasswordCompromise(password,customMessage){if(!password)return;const sha1Hash=(await(0,import_hash.createHash)(\"SHA-1\",\"hex\").digest(password)).toUpperCase();const prefix=sha1Hash.substring(0,5);const suffix=sha1Hash.substring(5);try{const{data,error}=await(0,import_fetch.betterFetch)(`https://api.pwnedpasswords.com/range/${prefix}`,{headers:{\"Add-Padding\":\"true\",\"User-Agent\":\"BetterAuth Password Checker\"}});if(error)throw new import_api.APIError(\"INTERNAL_SERVER_ERROR\",{message:`Failed to check password. Status: ${error.status}`});if(data.split(\"\\n\").some(line=>line.split(\":\")[0].toUpperCase()===suffix.toUpperCase()))throw import_api.APIError.from(\"BAD_REQUEST\",{message:customMessage||ERROR_CODES.PASSWORD_COMPROMISED.message,code:ERROR_CODES.PASSWORD_COMPROMISED.code})}catch(error){if((0,import_is_api_error.isAPIError)(error))throw error;throw new import_api.APIError(\"INTERNAL_SERVER_ERROR\",{message:\"Failed to check password. Please try again later.\"})}}__name(checkPasswordCompromise,\"checkPasswordCompromise\");const haveIBeenPwned=__name(options=>{const paths=options?.paths||[\"/sign-up/email\",\"/change-password\",\"/reset-password\"];return{id:\"have-i-been-pwned\",init(ctx){const originalHash=ctx.password.hash;return{context:{password:{...ctx.password,async hash(password){const c=await(0,import_context.getCurrentAuthContext)();if(!c.path||!paths.includes(c.path))return originalHash(password);await checkPasswordCompromise(password,options?.customPasswordCompromisedMessage);return originalHash(password)}}}}},options,$ERROR_CODES:ERROR_CODES}},\"haveIBeenPwned\");0&&(module.exports={haveIBeenPwned});\n})()\n","warnings":[],"map":{"version":3,"mappings":";suBAAA,+KAA2B,wCAC3B,eAAyB,+BACzB,mBAAsC,qCACtC,uBAAiC,+CACjC,gBAA2B,mCAC3B,iBAA4B,+BAG5B,MAAM,eAAc,qCAAiB,CAAE,qBAAsB,oFAAqF,CAAC,EACnJ,eAAe,wBAAwB,SAAU,cAAe,CAC/D,GAAI,CAAC,SAAU,OACf,MAAM,UAAY,QAAM,wBAAW,QAAS,KAAK,EAAE,OAAO,QAAQ,GAAG,YAAY,EACjF,MAAM,OAAS,SAAS,UAAU,EAAG,CAAC,EACtC,MAAM,OAAS,SAAS,UAAU,CAAC,EACnC,GAAI,CACH,KAAM,CAAE,KAAM,KAAM,EAAI,QAAM,0BAAY,wCAAwC,MAAM,GAAI,CAAE,QAAS,CACtG,cAAe,OACf,aAAc,6BACf,CAAE,CAAC,EACH,GAAI,MAAO,MAAM,IAAI,oBAAS,wBAAyB,CAAE,QAAS,qCAAqC,MAAM,MAAM,EAAG,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