Edit: /tmp/tsx-0/17887-ff9c42af22cb34477ebba3f84bdc57fdae4bfc73 (14575B)
{"code":"__filename=\"/opt/canhelp/node_modules/better-auth/dist/api/to-auth-endpoints.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 to_auth_endpoints_exports={};__export(to_auth_endpoints_exports,{toAuthEndpoints:()=>toAuthEndpoints});module.exports=__toCommonJS(to_auth_endpoints_exports);var import_is_api_error=require(\"../utils/is-api-error.mjs\");var import_context=require(\"@better-auth/core/context\");var import_env=require(\"@better-auth/core/env\");var import_error=require(\"@better-auth/core/error\");var import_defu=require(\"defu\");var import_instrumentation=require(\"@better-auth/core/instrumentation\");var import_better_call=require(\"better-call\");const defuReplaceArrays=(0,import_defu.createDefu)((obj,key,value)=>{if(Array.isArray(obj[key])&&Array.isArray(value)){obj[key]=value;return true}});const hooksSourceWeakMap=new WeakMap;function getOperationId(endpoint,key){if(!endpoint?.options)return key;const opts=endpoint.options;return opts.operationId??opts.metadata?.openapi?.operationId??key}__name(getOperationId,\"getOperationId\");function toAuthEndpoints(endpoints,ctx){const api={};for(const[key,endpoint]of Object.entries(endpoints)){api[key]=async context=>{const operationId=getOperationId(endpoint,key);const endpointMethod=endpoint?.options?.method;const defaultMethod=Array.isArray(endpointMethod)?endpointMethod[0]:endpointMethod;const run=__name(async()=>{const authContext=await ctx;const methodName=context?.method??context?.request?.method??defaultMethod??\"?\";const pathName=context?.path??endpoint.path??\"/:virtual\";let internalContext={...context,context:{...authContext,returned:void 0,responseHeaders:void 0,session:null},path:endpoint.path,headers:context?.headers?new Headers(context?.headers):void 0};return(0,import_instrumentation.withSpan)(`${methodName} ${pathName}`,{[import_instrumentation.ATTR_HTTP_ROUTE]:pathName,[import_instrumentation.ATTR_OPERATION_ID]:operationId},async()=>(0,import_context.runWithEndpointContext)(internalContext,async()=>{const{beforeHooks,afterHooks}=getHooks(authContext);const before=await runBeforeHooks(internalContext,beforeHooks,endpoint,operationId);if(\"context\"in before&&before.context&&typeof before.context===\"object\"){const{headers,...rest}=before.context;if(headers)headers.forEach((value,key2)=>{internalContext.headers.set(key2,value)});internalContext=defuReplaceArrays(rest,internalContext)}else if(before)return context?.asResponse?(0,import_better_call.toResponse)(before,{headers:context?.headers}):context?.returnHeaders?{headers:context?.headers,response:before}:before;internalContext.asResponse=false;internalContext.returnHeaders=true;internalContext.returnStatus=true;const result=await(0,import_context.runWithEndpointContext)(internalContext,()=>(0,import_instrumentation.withSpan)(`handler ${pathName}`,{[import_instrumentation.ATTR_HTTP_ROUTE]:pathName,[import_instrumentation.ATTR_OPERATION_ID]:operationId},()=>endpoint(internalContext))).catch(e=>{if((0,import_is_api_error.isAPIError)(e))return{response:e,status:e.statusCode,headers:e.headers?new Headers(e.headers):null};throw e});if(result&&result instanceof Response)return result;internalContext.context.returned=result.response;internalContext.context.responseHeaders=result.headers;const after=await runAfterHooks(internalContext,afterHooks,endpoint,operationId);if(after.response)result.response=after.response;if((0,import_is_api_error.isAPIError)(result.response)&&(0,import_env.shouldPublishLog)(authContext.logger.level,\"debug\"))result.response.stack=result.response.errorStack;if((0,import_is_api_error.isAPIError)(result.response)&&!context?.asResponse)throw result.response;return context?.asResponse?(0,import_better_call.toResponse)(result.response,{headers:result.headers,status:result.status}):context?.returnHeaders?context?.returnStatus?{headers:result.headers,response:result.response,status:result.status}:{headers:result.headers,response:result.response}:context?.returnStatus?{response:result.response,status:result.status}:result.response}))},\"run\");if(await(0,import_context.hasRequestState)())return run();else return(0,import_context.runWithRequestState)(new WeakMap,run)};api[key].path=endpoint.path;api[key].options=endpoint.options}return api}__name(toAuthEndpoints,\"toAuthEndpoints\");async function runBeforeHooks(context,hooks,endpoint,operationId){let modifiedContext={};for(const hook of hooks){let matched=false;try{matched=hook.matcher(context)}catch(error){const hookSource=hooksSourceWeakMap.get(hook.handler)??\"unknown\";context.context.logger.error(`An error occurred during ${hookSource} hook matcher execution:`,error);throw new import_error.APIError(\"INTERNAL_SERVER_ERROR\",{message:`An error occurred during hook matcher execution. Check the logs for more details.`})}if(matched){const hookSource=hooksSourceWeakMap.get(hook.handler)??\"unknown\";const path=context.path??endpoint?.path??\"/:virtual\";const result=await(0,import_instrumentation.withSpan)(`hook before ${path} ${hookSource}`,{[import_instrumentation.ATTR_HOOK_TYPE]:\"before\",[import_instrumentation.ATTR_HTTP_ROUTE]:path,[import_instrumentation.ATTR_CONTEXT]:hookSource,[import_instrumentation.ATTR_OPERATION_ID]:operationId},()=>hook.handler({...context,returnHeaders:false})).catch(e=>{if((0,import_is_api_error.isAPIError)(e)&&(0,import_env.shouldPublishLog)(context.context.logger.level,\"debug\"))e.stack=e.errorStack;throw e});if(result&&typeof result===\"object\"){if(\"context\"in result&&typeof result.context===\"object\"){const{headers,...rest}=result.context;if(headers instanceof Headers)if(modifiedContext.headers)headers.forEach((value,key)=>{modifiedContext.headers?.set(key,value)});else modifiedContext.headers=headers;modifiedContext=defuReplaceArrays(rest,modifiedContext);continue}return result}}}return{context:modifiedContext}}__name(runBeforeHooks,\"runBeforeHooks\");async function runAfterHooks(context,hooks,endpoint,operationId){for(const hook of hooks)if(hook.matcher(context)){const hookSource=hooksSourceWeakMap.get(hook.handler)??\"unknown\";const path=context.path??endpoint?.path??\"/:virtual\";const result=await(0,import_instrumentation.withSpan)(`hook after ${path} ${hookSource}`,{[import_instrumentation.ATTR_HOOK_TYPE]:\"after\",[import_instrumentation.ATTR_HTTP_ROUTE]:path,[import_instrumentation.ATTR_CONTEXT]:hookSource,[import_instrumentation.ATTR_OPERATION_ID]:operationId},()=>hook.handler(context)).catch(e=>{if((0,import_is_api_error.isAPIError)(e)){const headers=e[import_better_call.kAPIErrorHeaderSymbol];if((0,import_env.shouldPublishLog)(context.context.logger.level,\"debug\"))e.stack=e.errorStack;return{response:e,headers:headers?headers:e.headers?new Headers(e.headers):null}}throw e});if(result.headers)result.headers.forEach((value,key)=>{if(!context.context.responseHeaders)context.context.responseHeaders=new Headers({[key]:value});else if(key.toLowerCase()===\"set-cookie\")context.context.responseHeaders.append(key,value);else context.context.responseHeaders.set(key,value)});if(result.response)context.context.returned=result.response}return{response:context.context.returned,headers:context.context.responseHeaders}}__name(runAfterHooks,\"runAfterHooks\");function getHooks(authContext){const plugins=authContext.options.plugins||[];const beforeHooks=[];const afterHooks=[];const beforeHookHandler=authContext.options.hooks?.before;if(beforeHookHandler){hooksSourceWeakMap.set(beforeHookHandler,\"user\");beforeHooks.push({matcher:__name(()=>true,\"matcher\"),handler:beforeHookHandler})}const afterHookHandler=authContext.options.hooks?.after;if(afterHookHandler){hooksSourceWeakMap.set(afterHookHandler,\"user\");afterHooks.push({matcher:__name(()=>true,\"matcher\"),handler:afterHookHandler})}const pluginBeforeHooks=plugins.flatMap(plugin=>(plugin.hooks?.before??[]).map(h=>{hooksSourceWeakMap.set(h.handler,`plugin:${plugin.id}`);return h}));const pluginAfterHooks=plugins.flatMap(plugin=>(plugin.hooks?.after??[]).map(h=>{hooksSourceWeakMap.set(h.handler,`plugin:${plugin.id}`);return h}));if(pluginBeforeHooks.length)beforeHooks.push(...pluginBeforeHooks);if(pluginAfterHooks.length)afterHooks.push(...pluginAfterHooks);return{beforeHooks,afterHooks}}__name(getHooks,\"getHooks\");0&&(module.exports={toAuthEndpoints});\n})()\n","warnings":[],"map":{"version":3,"mappings":";suBAAA,0LAA2B,qCAC3B,mBAA6E,qCAC7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