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.48 kB
JavaScript
const e=require(`./upload-config-BQXhlkY1.js`),t=require(`./client-T7N63eRp.js`);var n=class{constructor(){t.H(this,`checks`,[])}async runHealthChecks(e){this.checks=[];let n=Date.now();t.j.info(`Starting health checks`),await this.checkConfiguration(e),await this.checkEnvironment(),e&&await this.checkConnectivity(e),await this.checkPerformance();let r=this.calculateSummary(),i=this.determineOverallStatus(r),a=Date.now()-n;return t.j.info(`Health checks completed in ${a}ms`,{status:i,summary:r}),{status:i,checks:[...this.checks],summary:r,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 Promise.resolve().then(()=>require(`./client-LvGTR9f1.js`)),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 t=performance.now();try{if(!e.r.isMetricsEnabled()){this.addCheck(`Performance Metrics`,`warn`,`Metrics collection is disabled`);return}let t=e.r.getAggregatedMetrics();if(t.totalOperations===0){this.addCheck(`Performance Metrics`,`pass`,`No operations recorded yet`);return}t.successRate<90?this.addCheck(`Success Rate`,`warn`,`Success rate is ${t.successRate.toFixed(1)}% (below 90%)`,{metrics:t}):this.addCheck(`Success Rate`,`pass`,`Success rate is ${t.successRate.toFixed(1)}%`),t.averageDuration>5e3?this.addCheck(`Performance`,`warn`,`Average operation duration is ${t.averageDuration.toFixed(1)}ms (above 5s)`,{metrics:t}):this.addCheck(`Performance`,`pass`,`Average operation duration is ${t.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()-t)}}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()}};const r=new n,i=e=>r.runHealthChecks(e),a=e=>r.getHealthReport(e);exports.PushduckError=t.M,exports.S3ArraySchema=e.l,exports.S3FileSchema=e.u,exports.S3ImageSchema=e.d,exports.S3ObjectSchema=e.f,exports.S3Route=e.m,exports.S3Schema=e.p,exports.StorageInstance=e.s,exports.createConfigError=t.N,exports.createFileError=t.P,exports.createNetworkError=t.F,exports.createProvider=e.g,exports.createS3Client=t.n,exports.createS3Error=t.I,exports.createS3RouterWithConfig=e.h,exports.createStorage=e.c,exports.createUploadConfig=e.t,exports.endOperation=e.n,exports.getHealthReport=a,exports.getProviderEndpoint=e._,exports.healthChecker=r,exports.isConfigError=t.L,exports.isFileError=t.R,exports.isPushduckError=t.z,exports.isS3Error=t.B,exports.logger=t.j,exports.metrics=e.r,exports.recordOperation=e.i,exports.resetS3Client=t.T,exports.runHealthCheck=i,exports.startOperation=e.a,exports.trackOperation=e.o,exports.validateProviderConfig=e.v,exports.wrapAsync=t.V;