pushduck
Version:
The fastest way to add file uploads to any web application. Enterprise security, edge-ready. Works with 16+ frameworks and 5+ storage providers. No heavy AWS SDK required.
16 lines (14 loc) • 6.43 kB
JavaScript
import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,u as g,v as _}from"./upload-config-BhhgIARR.mjs";import{B as v,F as y,H as b,I as x,L as S,M as C,N as w,P as T,R as E,T as D,V as O,j as k,n as A,z as j}from"./client-CPi8kVKS.mjs";const M=new class{constructor(){b(this,`checks`,[])}async runHealthChecks(e){this.checks=[];let t=Date.now();k.info(`Starting health checks`),await this.checkConfiguration(e),await this.checkEnvironment(),e&&await this.checkConnectivity(e),await this.checkPerformance();let n=this.calculateSummary(),r=this.determineOverallStatus(n),i=Date.now()-t;return k.info(`Health checks completed in ${i}ms`,{status:r,summary:n}),{status:r,checks:[...this.checks],summary:n,timestamp:new Date}}async checkConfiguration(e){let t=performance.now();try{if(!e){this.addCheck(`Configuration`,`warn`,`No configuration provided for validation`);return}let t=[`provider`,`accessKeyId`,`secretAccessKey`,`bucket`].filter(t=>!e[t]);if(t.length>0){this.addCheck(`Configuration`,`fail`,`Missing required fields: ${t.join(`, `)}`,{missingFields:t});return}let n=this.validateProviderConfig(e);if(!n.valid){this.addCheck(`Configuration`,`fail`,`Provider configuration invalid: ${n.errors.join(`, `)}`,{errors:n.errors});return}this.addCheck(`Configuration`,`pass`,`Configuration is valid`)}catch(e){this.addCheck(`Configuration`,`fail`,e instanceof Error?e.message:`Configuration check failed`)}finally{this.updateCheckDuration(`Configuration`,performance.now()-t)}}async checkEnvironment(){let e=performance.now();try{let e=process.version,t=parseInt(e.slice(1).split(`.`)[0]);t<16?this.addCheck(`Node.js Version`,`fail`,`Node.js ${e} is not supported. Minimum version: 16.0.0`):t<18?this.addCheck(`Node.js Version`,`warn`,`Node.js ${e} is supported but consider upgrading to v18+ for better performance`):this.addCheck(`Node.js Version`,`pass`,`Node.js ${e} is supported`);let n=process.memoryUsage(),r=Math.round(n.heapUsed/1024/1024),i=Math.round(n.heapTotal/1024/1024);r>512?this.addCheck(`Memory Usage`,`warn`,`High memory usage: ${r}MB used of ${i}MB total`,{memoryUsage:n}):this.addCheck(`Memory Usage`,`pass`,`Memory usage is normal: ${r}MB used of ${i}MB total`),typeof performance>`u`?this.addCheck(`Performance API`,`warn`,`Performance API not available - metrics collection may be limited`):this.addCheck(`Performance API`,`pass`,`Performance API is available`)}catch(e){this.addCheck(`Environment`,`fail`,e instanceof Error?e.message:`Environment check failed`)}finally{this.updateCheckDuration(`Environment`,performance.now()-e)}}async checkConnectivity(e){let t=performance.now();try{let{validateS3Connection:t}=await import(`./client-Cl6wG8WF.mjs`),n=await t(e);n.success?this.addCheck(`S3 Connectivity`,`pass`,`Successfully connected to S3`):this.addCheck(`S3 Connectivity`,`fail`,`Failed to connect to S3: ${n.error}`,{error:n.error})}catch(e){this.addCheck(`S3 Connectivity`,`fail`,e instanceof Error?e.message:`Connectivity check failed`)}finally{this.updateCheckDuration(`S3 Connectivity`,performance.now()-t)}}async checkPerformance(){let e=performance.now();try{if(!p.isMetricsEnabled()){this.addCheck(`Performance Metrics`,`warn`,`Metrics collection is disabled`);return}let e=p.getAggregatedMetrics();if(e.totalOperations===0){this.addCheck(`Performance Metrics`,`pass`,`No operations recorded yet`);return}e.successRate<90?this.addCheck(`Success Rate`,`warn`,`Success rate is ${e.successRate.toFixed(1)}% (below 90%)`,{metrics:e}):this.addCheck(`Success Rate`,`pass`,`Success rate is ${e.successRate.toFixed(1)}%`),e.averageDuration>5e3?this.addCheck(`Performance`,`warn`,`Average operation duration is ${e.averageDuration.toFixed(1)}ms (above 5s)`,{metrics:e}):this.addCheck(`Performance`,`pass`,`Average operation duration is ${e.averageDuration.toFixed(1)}ms`)}catch(e){this.addCheck(`Performance Metrics`,`fail`,e instanceof Error?e.message:`Performance check failed`)}finally{this.updateCheckDuration(`Performance Metrics`,performance.now()-e)}}validateProviderConfig(e){let t=[];switch(e.provider.provider){case`aws`:e.provider.region||t.push(`AWS region is required`);break;case`cloudflare-r2`:e.provider.endpoint||t.push(`Cloudflare R2 endpoint is required`);break;case`digitalocean-spaces`:e.provider.endpoint||t.push(`DigitalOcean Spaces endpoint is required`);break;case`minio`:e.provider.endpoint||t.push(`MinIO endpoint is required`);break;case`s3-compatible`:e.provider.endpoint||t.push(`S3-compatible endpoint is required`);break;default:t.push(`Unsupported provider: ${e.provider.provider}`)}return{valid:t.length===0,errors:t}}addCheck(e,t,n,r){this.checks.push({name:e,status:t,message:n,details:r})}updateCheckDuration(e,t){let n=this.checks.find(t=>t.name===e);n&&(n.duration=t)}calculateSummary(){return{total:this.checks.length,passed:this.checks.filter(e=>e.status===`pass`).length,warnings:this.checks.filter(e=>e.status===`warn`).length,failures:this.checks.filter(e=>e.status===`fail`).length}}determineOverallStatus(e){return e.failures>0?`error`:e.warnings>0?`warning`:`healthy`}getHealthReport(e){let t={healthy:`✅`,warning:`⚠️`,error:`❌`},n={pass:`✅`,warn:`⚠️`,fail:`❌`};return`
${t[e.status]} Pushduck Health Check Report
==========================================
Status: ${e.status.toUpperCase()}
Timestamp: ${e.timestamp.toISOString()}
Summary:
- Total Checks: ${e.summary.total}
- Passed: ${e.summary.passed}
- Warnings: ${e.summary.warnings}
- Failures: ${e.summary.failures}
Detailed Results:
${e.checks.map(e=>{let t=e.duration?` (${e.duration.toFixed(1)}ms)`:``;return`${n[e.status]} ${e.name}: ${e.message}${t}`}).join(`
`)}
`.trim()}},N=e=>M.runHealthChecks(e),P=e=>M.getHealthReport(e);export{C as PushduckError,c as S3ArraySchema,g as S3FileSchema,r as S3ImageSchema,i as S3ObjectSchema,l as S3Route,f as S3Schema,m as StorageInstance,w as createConfigError,T as createFileError,y as createNetworkError,a as createProvider,A as createS3Client,x as createS3Error,o as createS3RouterWithConfig,n as createStorage,h as createUploadConfig,u as endOperation,P as getHealthReport,e as getProviderEndpoint,M as healthChecker,S as isConfigError,E as isFileError,j as isPushduckError,v as isS3Error,k as logger,p as metrics,s as recordOperation,D as resetS3Client,N as runHealthCheck,t as startOperation,d as trackOperation,_ as validateProviderConfig,O as wrapAsync};